Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have over 1000 .csv files in a folder on Debian Squeeze. I am trying to create a new .csv file containing ONLY the first rows of each of these 1000 .csv files.

I tried:

read -r firstline < sourcefile_1.csv > headers.csv

But that only created a blank file. (And even if it did work, I would have copied only the first row of just one file.)

How do I write a command that copies the first rows of all 1000 files in the folder and add it to the new .csv file?

Thanks in advance!

share|improve this question

1 Answer 1

up vote 4 down vote accepted

head -q -n 1 *.csv > output.csv
-q supresses the headers that normally get printed, -n 1 prints only the first line

share|improve this answer
    
That worked! Fantastic! Thank you. –  Spartanblogger Dec 4 '12 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.