Scripting: split file into 12 lines array
Hi,
I need to split a file into an array. The split is at every 12 line. eg. line 1 line 2 ... line 24 then the array will look something like items[0] = line 1 ... line 12 items[1] = line 13 ... line 24 right now I am read line by line from the file and putting into an array. This is a little slow. If there is a better way, please point me in the right direction. Thanks, Mike |
tell us what exactly what problem you are solving.
|
Quote:
If the lines are uniform, you could theoretically do something involving bytes or size, but that strikes me as an unlikely possibility. |
I don't know if it will run faster, but you could use something like this (untested code, just for concept)
Code:
INDEX=0 |
Quote:
Please see the thread below: sed script to parse a file into smaller files with set # of lines Kevin Barry |
I did some testing a while back, and found perl was faster at subsetting a (huge) file than sed, even if both were stopped after the requisite lines (only) were found rather than continuing to read.
As usual, YMMV. |
Quote:
1) lose the cat because its useless, 2) avoid using bash's while read loop to read big files. 3) and if bash solution is desired, no need to call external sed command. use bash's own string substitution. 4) or use awk |
Quote:
Kevin Barry |
Quote:
|
Quote:
Kevin Barry |
Quote:
Code:
cat $file | while.... Code:
while read ... Code:
exec 4<"$filename" 3) I am not sure what that sed line is doing ie s/./&/, care to explain? 4) Have already provided awk suggestion in that thread. |
Quote:
Quote:
Kevin Barry |
Quote:
Code:
awk 'NR%4==1{++c}{print $0 > "file-"c".txt"}' file Code:
$ more file the awk one liner above summarizes what OP did will those bunch of seds Code:
sed -n '1,4000000 s/./&/w $FileName.01' $FileName Quote:
Quote:
|
All times are GMT -5. The time now is 06:55 PM. |