LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX
User Name
Password
Other *NIX This forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.

Notices

Reply
 
Search this Thread
Old 03-10-2008, 11:16 PM   #1
anurade
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
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
 
Old 03-10-2008, 11:32 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,351

Rep: Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041
"head n=1" ???.
Stick it in a (bash) loop. Shouldn't be too onerous.
 
Old 03-31-2008, 10:55 AM   #3
rnturn
Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0), SuSE (10.x, 11.x, 12.2), Solaris (8-10), Tru64
Posts: 949

Rep: Reputation: 51
Quote:
Originally Posted by anurade View Post
... 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash read a given line number from text bendeco13 Programming 7 08-31-2012 03:49 PM
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 01:42 PM
Shell Scripting: How to pick lines out of files by line number. Louie55 Programming 3 03-22-2005 06:18 PM
How can I read pdf files at the command line? hansi umayangan Linux - General 8 09-02-2004 07:27 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM


All times are GMT -5. The time now is 06:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration