mardi 13 janvier 2015

Awk - output the second line of a number of .dat files to one file


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.dat



2 5

6 9

7 1


file2.dat



3 7

8 4

1 3


I want to end up with a file containing all of the second lines. i.e.


output.dat



6 9

8 4


What 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 be



8 4


my shell script looks like this:


post.sh



TEND = 80

TINDX = 0

while [ $TINDX - lt $TEND]; do

awk '{ print NR==2 "input-$TINDX.dat > output.dat

TINDX = $((TINDX+1))

done


many thanks for any help with this



Aucun commentaire:

Enregistrer un commentaire