LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Other *NIX (https://www.linuxquestions.org/questions/other-%2Anix-55/)
-   -   Efficient way to read only 1st line from number of files (https://www.linuxquestions.org/questions/other-%2Anix-55/efficient-way-to-read-only-1st-line-from-number-of-files-627119/)

anurade 03-10-2008 11:16 PM

Efficient way to read only 1st line from number of files
 
Hi,

I am struck up with some problem. I am analyzing on an efficient way to read number of files. Actually I want to read only the first line from each of them.
There could be hundreds of them in the directory/sub-directories; but not huge in size.
Can anyone suggest a way I can do it without compromising too much on memory and performance.

Thanks in advance.

/Anu

syg00 03-10-2008 11:32 PM

"head n=1" ???.
Stick it in a (bash) loop. Shouldn't be too onerous.

rnturn 03-31-2008 10:55 AM

Quote:

Originally Posted by anurade (Post 3084613)
... I want to read only the first line from each of them.
There could be hundreds of them in the directory/sub-directories

I'd use:
Code:

find . -type f -exec head -1 {} \;
Or, if you need the name of the file as its first line:
Code:

find . -type f | while read FN
do
  echo "$FN : head -1 $FN"
done



All times are GMT -5. The time now is 09:37 AM.