Split a file with awk

Hi!

I have a file like this:

a,b,c,12,d,e
a,b,c,13,d,e
a,b,c,14,d,e
a,b,c,15,d,e
a,b,c,16,d,e
a,b,c,17,d,e

I need to split that file in two:
If field 4 is equal or higher than 14 that row goes to one file and if it is equal or higher than 15 to another.

Can anyone point me in the right direction?
Thanks.

easy:

awk '($4 >= 14) { print >"file1"}
($4 < 14) { print > "file2"}' datafile

Adding the field separator worked like a charm.

Thank you.

1 Like