Get N'th line of multiple files in linux

Get rid of the useless echo, the incorrect exit and the redundant print:

awk 'FNR == 3' test*.csv

You should use

awk 'FNR == 3 { print; nextfile }' test*.csv >> last_file.csv

The problem is that when you use exit, it stops awk from processing input completely. The nextfile tells awk to stop processing the current file and go to the next file. The echo command as you are using it is not necessary.

Read more here:

http://www.gnu.org/software/gawk/manual/html_node/Nextfile-Statement.html


This might work for you (GNU sed):

sed -sn 3p test*.csv >> last_file.csv

Tags:

Linux

Csv

Awk

Sed

Echo