LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-29-2003, 12:09 PM   #1
davi_cabral
LQ Newbie
 
Registered: Jul 2003
Location: Rio
Distribution: RedHat 7.2
Posts: 21

Rep: Reputation: 15
reading a single line of a text file


Hi people...
How can I read a single line of a text file?

A text file has a column with several lines of numbers, for example:

189025
89052098
43908
32
2308945
09432
.......

I need a command that returns me the i-th line of this file, such as line #3, 180, 0 or 1.
These numbers change with time, so I cannot use their contents as reference.

Thanks for help
Davi
 
Old 10-29-2003, 12:24 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
sed (among others) can do this:

sed -n '2p' <file>

The second line of file <file> is shown. From within a script you can change the 2 into whatever linenumber you want.

Ranges are allowed as well:

sed -n '2,4p' <file>

shows lines 2, 3 and 4 of file <file>
 
  


Reply



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
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
File reading line by line and compare Goni Linux - Software 14 09-21-2005 12:24 AM
Retrieve only a single line from a file rose_bud4201 Programming 4 06-22-2005 06:26 PM
Removing Text in a single line starting with one pattern ending on another mgwheeler Programming 13 08-03-2004 04:36 PM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:25 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration