-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
39 lines (26 loc) · 1.01 KB
/
README
File metadata and controls
39 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
This little Perl script takes a delimited text file which has tabular data in it -- first row with columns followed by any number of rows -- and splits it to any number of file, each containing X number of rows, but always keeping the first row as the columns row.
The script can take one or two arguments: the first argument must be the filename of the source file. The second argument can be a the number of rows to put in each file. If the number of lines per file is not given 5000 is used as the default.
For example, if you have the following data file in the file "names_and_ages.txt":
Name Age
Mary 20
Bob 30
Jake 12
Tod 45
Heidi 87
Tom 54
and you run the script:
./psplit.pl names_and_ages.txt 2
You'll get three files as an output:
names_and_ages1.txt:
Name Age
Mary 20
Bob 30
names_and_ages2.txt:
Name Age
Jake 12
Tod 45
names_and_ages3.txt:
Name Age
Heidi 87
Tom 54
I wrote this to solve a specific problem I had, it's my first attempt at using Perl, so I'm sure there must be better ways to do this.