The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read the file line by line kittusri9 Shell Programming and Scripting 3 04-24-2008 05:26 AM
How to read element of line of file ahjiefreak High Level Programming 1 04-20-2008 11:21 AM
How to read last line of a txt file? yongho UNIX for Dummies Questions & Answers 2 06-13-2005 10:20 AM
Read a file line by line VENC22 UNIX for Dummies Questions & Answers 2 05-12-2005 10:13 AM
How to read from a file line by line and do stuff spaceship Shell Programming and Scripting 4 03-17-2005 05:47 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-14-2005
Registered User
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
read line from file

I need to read one specific line from a file. I want to be able to get the entire line by its line number. Does anyone know how to do that?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-14-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 627
sed -n '1p' $filename
Reply With Quote
  #3 (permalink)  
Old 04-14-2005
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
My question is how would you know what line # the data was in? It may be much easier if you knew a word or pattern from that line and then use grep.
__________________
My brain is your brain
Reply With Quote
  #4 (permalink)  
Old 04-14-2005
Registered User
 

Join Date: Jan 2005
Posts: 13
If you know the pattern , then the following would work.

sed -n '/Put pattern Here/{
=
p
}' Filename.
Reply With Quote
  #5 (permalink)  
Old 04-14-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,226
To get the 3rd line from a file...
Code:
awk NR==3 file1
Reply With Quote
  #6 (permalink)  
Old 04-14-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Or with sed

Code:
line_number=7
sed -n "${line_number}p" file_name
Cheers
ZB
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0