As part of a bigger task, I had to read thru a file and separate records into various batches based on a field. Specifically, separate records based on the value in the batch field as defined below. The batch field left-justified numbers.
The datafile is here
> cat infile
12345 1 John Smith *
109 2 Joe Doe *
1-9089 13Harry Can *
14-12 5 Mary Will *
43-4-5 13Kerry Lay *
50505 1 Wanda Round *
My script is here (and includes info on file layout)
This is all greatly simplified from my overall task which was then to perform data manipulations on the separated files. However, my small script above with the awk command merely creates 15 files that are empty.
So, what is wrong with the syntax?
I tried the first suggestion, and it too did not quite separate the records. But the 2nd suggestion (thanks Franklin52) seemed to do the trick. I also fixed output filename to make the names easier to read (instead of _1 thru _15 I now create _01 thru _15)
Final code=
Finally, a look at the output shows that the records were put into the correct output files:
> grep "*" outfile*
outfile_01:12345 1 John Smith *
outfile_01:50505 1 Wanda Round *
outfile_02:109 2 Joe Doe *
outfile_05:14-12 5 Mary Will *
outfile_13:1-9089 13Harry Can *
outfile_13:43-4-5 13Kerry Lay *
which displays filename: and data records (remember, I placed a * at the end of every data record)