From: Reid Thompson Date: 2006-11-30T05:26:28+09:00 Subject: Re: Splitting a CSV file into 40,000 line chunks On Thu, 2006-11-30 at 04:44 +0900, Drew Olson wrote: > Reid Thompson wrote: > > On Thu, 2006-11-30 at 02:25 +0900, ChrisH wrote: > >> Also since he's feeding Excel this is most likely on Windows rather > >> than *NIX > > not a show stopper.. > > http://www.research.att.com/sw/tools/uwin/ > > > > http://unxutils.sourceforge.net/ > > Reid - > > I also have cygwin installed on my box, so if there is a simply way to > do this in unix I'd love to know. My unix is rusty (that's being > generous). > rthompso@jhereg:~$ cat splitandhead #!/bin/bash fname=$1 split -l 4000 -a 6 -d $fname $fname for file in `ls ${fname}0*` do sed -e '1i\Col1 Col2 Col3 Col4\' $file > ${file}.tmp mv ${file}.tmp $file done rthompso@jhereg:~$ head testsed this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test rthompso@jhereg:~$ wc testsed 40140 160560 602100 testsed rthompso@jhereg:~$ time ./splitandhead testsed real 0m0.499s user 0m0.140s sys 0m0.092s rthompso@jhereg:~$ head -2 testsed0000* ==> testsed000000 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000001 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000002 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000003 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000004 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000005 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000006 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000007 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000008 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000009 <== Col1 Col2 Col3 Col4 this is a test ==> testsed000010 <== Col1 Col2 Col3 Col4 this is a test rthompso@jhereg:~$