Writing a script that will take the first line from each file and store it in an output file

Hi,

I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks!


for i in *.txt 
do
awk 'NR == 1' $i >> output 
done 

do you want to put this in one file only?
if yes use above solution.

if no.. use

awk 'NR == 1' $i > out$i

Without an exit statement, those awk scripts could do a lot of pointless i/o if the files are large.

Also, performing the redirect operation once (with an exec before the for-loop or by appending the redirection to done ) would save a little work too.

Regards,
Alister