Use:
BEGIN {
}
NR>6{
process here
}
END {
}
In awk, NR
is the line number. To skip processing for the first six, we add the condition NF>6
. When this condition is false, which it is for the first six lines, the lines are not processed.
Processing multiple files
Suppose that we have a folder full of text files named 000.txt to 181.txt. Here is an example of processing all of them with the same awk script and send them to respective output files (output000.txt - output181.txt):
awk 'NR>6{print>("output" FILENAME)}' {000..181}.txt
If we are using bash
, then {000..181}.txt
will expand to the names of our 182 input files.
In awk (this may require GNU awk), FILENAME
is the name of the input file that awk is currently working on. Thus ("output" FILENAME)
is the name of our current output file.
Intended just as an example, the above simply prints all but the first six lines of the input file to the output file. More complicated programs would use the same principles.
Extra: To process every file in the directory, regardless of its file name, use:
awk 'NR>6{print>("output" FILENAME)}' *
I have a folder full of text files named 000.txt to 181.txt. How can I process all of them (on the command line) with the same awk script (program.awk) and send them to their respective output files (output000.txt - output181.txt)? – amatek – 2015-04-25T02:59:29.497
@amatek See the updated answer for an example of processing input files 000.txt to 181.txt into output files output000.txt - output181.txt. – John1024 – 2015-04-25T03:37:46.960
Thanks a lot. How about processing 'every' file in the folder despite the characters in the name? – amatek – 2015-04-25T11:51:13.963
@amatek See the end of the updated answer for processing 'every' file. – John1024 – 2015-04-25T18:56:29.637