Now if it were
me, I'd put the AWK programming part into a separate ".awk" file
(e.g. splitemup.awk) and refer to it on the command line instead of putting the program literally into quotes. I simply find things easier to manage that way,
e.g.:
awk splitemup.awk SIZE=5 FILE=split input_file
(referring to a previous post in this thread).
But AWK usually is
the tool de jour for requests like these. It's designed for line-by-line processing and splitting-up of text files and it can do the job in all sorts of different ways.
As you can see from the recently-posted examples, AWK programs consist of a series of rules:
pattern_to_match or condition { actions to execute in this case }
Conditions cited in the examples below include
NR==1 ("the record-number is '1'") or
(NR % SIZE) == 0 ("the record-number is an even multiple of SIZE, which is defined on the command-line in the example to be equal to 5"). The final rule in the example contains
no condition at all and so it is always executed.
Not surprisingly, AWK's condition-testing abilities are considerable. String patterns called
regular expressions (drop that term within a Unix-geek's earshot only at your own peril!) allow all sorts of pattern-recognition and string-extraction to be done very easily.
(And if you document them thoroughly enough at the time, you can actually remember what the patterns mean!)
You can therefore use this tool in a
lot of useful ways; for example, if a legacy application produces a "printed report" that you can direct to a file, you can cabbage data out of the report line-by-line. (Sometimes the only way to get what you need.) It's "definitely a tool to get to know," and it's readily downloadable for all kinds of platforms
(even ...
... Windows!).