Solved copy only first line of 200 text files

October 24, 2011 at 03:08:31
Specs: Mac OSX
I have about 200 text files of which I want to copy only the first line into a new file. So the new file (only one!) is supposed to contain 200 lines: the first line of each of the 200 files.
I thought about using awk or a shell script, but I'm not experienced enough to find out how exactly this in done. Can anyone help?

See More: copy only first line of 200 text files

Report •

October 24, 2011 at 11:53:19
✔ Best Answer
I am not a Mac guy, but sed is one way of printing the first line in a file:

cd <your directory>
rm -f ./newfile.txt
for myfile in *
   sed -n '1p' $myfile >> ./newfile.txt

Report •

October 25, 2011 at 06:42:05
Thanks a lot, this worked perfectly!

Report •
Related Solutions

Ask Question