Awk - output the second line of a number of .dat files to one file
Remove while
loop and make use of shell brace expansion and also FNR
, a built-in awk
variable:
awk 'FNR==2{print $0 > "output.dat"}' file{1..80}.dat
What about ...
head -n 2 input.dat | tail -n 1 | awk
...
sed
would be enough:
sed -sn 2p file{1..80}.dat > output.dat
-s
option is needed to print 2nd line from each file, otherwise only 2nd line of first file will be printed.