Split a text file by its entries

Posted by Alexx Hardt on Ask Ubuntu See other posts from Ask Ubuntu or by Alexx Hardt
Published on 2011-03-02T11:59:40Z Indexed on 2011/03/02 15:33 UTC
Read the original article Hit count: 320

Filed under:

Hi,
I'm trying to analyze an enormous text file (1.6GB), whose data lines look like this:

20090118025859 -2.400000 78.100000 1023.200000 0.000000
20090118025900 -2.500000 78.100000 1023.200000 0.000000
20090118025901 -2.400000 78.100000 1023.200000 0.000000

I don't even know how many lines there are. But I'm trying to split the file by date. The left number is a time stamp (these lines are from 2009, January 18th).
How can I split this file into pieces according to the date?

Everything I know would be to grep file '20090118*' > data20090118.dat , but there sure is a way to do all the dates at once, right?

The number of entries per date differ, so using split with a constant number won't work.

Thanks in advance,
Alex

© Ask Ubuntu or respective owner

Related posts about shell-scripting