Computing.Net > Forums > Unix > extract a specific line from file

extract a specific line from file

Reply to Message Icon

Original Message
Name: Aristo
Date: July 29, 2003 at 22:03:41 Pacific
Subject: extract a specific line from file
OS: Unix
CPU/Ram: ?
Comment:

hi,

can anyone teach me how to extract a specific line from an input file?

what utility should I use?

btw, I'm using Bourne Shell.


Report Offensive Message For Removal


Response Number 1
Name: Don Arnett
Date: July 29, 2003 at 22:25:11 Pacific
Reply: (edit)

It depends upon how you want to recognize the specific line. Do you want the fourth line from a file?? Do you want a line that contains a specific phrase?


Report Offensive Follow Up For Removal

Response Number 2
Name: Aristo
Date: July 29, 2003 at 22:29:47 Pacific
Reply: (edit)

just a normal line, not by delimeter...

for example, the 4th line of an input file..

thanks


Report Offensive Follow Up For Removal

Response Number 3
Name: f
Date: July 29, 2003 at 23:37:46 Pacific
Reply: (edit)

How about combination of head and tile in a pipe?
Say, you need 4th line:

head -n 4 your_file | tail -n 1



Report Offensive Follow Up For Removal

Response Number 4
Name: Aristo
Date: July 30, 2003 at 00:29:48 Pacific
Reply: (edit)

it works..

thank you very much.


Report Offensive Follow Up For Removal

Response Number 5
Name: David Perry
Date: July 30, 2003 at 08:04:00 Pacific
Reply: (edit)

lineno=10

sed -n ${lineno}p infile > outfile


Report Offensive Follow Up For Removal


Response Number 6
Name: HRCafe
Date: August 5, 2003 at 05:45:21 Pacific
Reply: (edit)

How about extracting the last line of a file. For example, I'm ftp'ing a file from UNIX to an NT box and an extra line is being added to the end of the file on the NT box. All it is is a blank line. I'm guessing this is a tranmission issue but does anyone know how to correct it? Please let me know your thoughts... Thanks!!!


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: extract a specific line from file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge