I have a file which is about 10 gigs and therefore can not be process it in my beloved excel. I need to cut this file in multiple parts based on the first number. For example the file looks something like this.


where the dots represent the fact that there are approximatly 200 lines following with 0.213. What I actually want to achieve is that I use awk, csplit or something like that. to split this huge file into multiple smaller files purely based on the first number. so..... 0.213 and 0.653 should be placed in the one file and 1.213 and whatever follows which starts with 1.xxx in the next file.

1 Answer 1


With awk, you'd do:

awk '{file = "output" substr($0, 1, 1) ".txt"; print > file}' < input.txt

Note that lines for 10.123 will go into output1.txt just like the lines for 1.123 or 11.123, 123123.123...

Alternatively, you could do:

awk -F'[.;]' '{file = "output" $1 ".txt"; print > file}' < input.txt

For the files to be named based on the content of the line up to the first . or ; (lines starting with 10.123;... or 10;... going into output10.txt).

  • thank you for your replay. I do indeed want 10.123 and 11.123 to be separated into separate files. Would that last command satisfy that?
    – Zak.M
    Apr 24, 2018 at 9:19
  • is there any reason you are not using awk '{print >"output" substr($0, 1, 1) ".txt"}' infile? Apr 24, 2018 at 11:20
  • @αғsнιη, iirc some awk implementations (OpenBSD?) struggle to differentiate the ">" redirection operator from the ">" comparison operator in some non-simple contexts. In doubt, I make sure the target of a redirection is a simple variable. Apr 24, 2018 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .