I have searched through previously asked questions and can't find an answer to what I am trying to do. note, I am new to linux.I have multiple files something like: (in reality i have 80)file1.dat2 56 97 1file2.dat3 78 41 3I want to end up with a file containing all of the second lines. i.e.output.dat6 98 4What i have so far loops though the file names but then over-writes the file before it. e.g. the output of the above files would just be8 4my shell script looks like this:post.shTEND = 80TINDX = 0while [ $TINDX - lt $TEND]; doawk '{ print NR==2 input-$TINDX.dat > output.datTINDX = $((TINDX+1))donemany thanks for any help with this
Awk - output the second line of a number of .dat files to one file
shell script;command line;text processing;awk;io redirection
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