Reputation: 35
I have a nice .awk script that takes the 2nd $2 value and prints it. Because the data in the .txt files only go down 8192 lines, any lines after that are irrelevant (the script takes care of that.) I have 400+ .tst files that need to have the same thing done and have the ouput's placed into a single file. So how would I go through every .tst file in the current directory? I tried piping the cat output to a single line version of the script but it only processed the first file. Any suggestions?
BEGIN{
}
{
print $2 "\n";
if (NR==8192)
exit;
}
END {
print NR "\n";
}
Upvotes: 1
Views: 179
Reputation: 85865
Just glob all the .tst
files in the current directory and redirect the output to outfile
:
$ awk 'FNR<=8192{print $2"\n";next}{print FNR"\n";nextfile}' *.tst > outfile
Upvotes: 1
Reputation: 77145
This should work -
awk 'FNR<=8192{ print $2 }' *.tst > finalfile
Upvotes: 3