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
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 05:29 AM
Extract a line from a file using the line number zambo Shell Programming and Scripting 1 05-01-2008 10:39 AM
extract a line from a file using the line number grandtheftander Shell Programming and Scripting 6 02-06-2008 03:12 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-20-2007 10:29 PM
Get line form file by line number corny Shell Programming and Scripting 3 08-25-2006 09:18 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
Getting a line of a file by number

I was wondering if their is a command that will output a line of a file by number. I mean i know how number a file but what i'm looking for is to pull a line out of a file by refering to its line number. Is their anyway of doing this. Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 03-30-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
sed1liners
Code:
 # print line number 52
 sed -n '52p'                 # method 1
 sed '52!d'                   # method 2
 sed '52q;d'                  # method 3, efficient on large files
Reply With Quote
  #3  
Old 03-30-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
Thanks that helpled me out
Reply With Quote
  #4  
Old 03-30-2006
Registered User
 

Join Date: Mar 2006
Posts: 2
Quote:
Originally Posted by Quesa
Thanks that helpled me out

Hi,

I have a similar problem.I want to display few lines say from line 10 to 15th in a 60 line file.The above command is not taking more than one address so suitable to display one line only.Can you help me.
Thanks,
Reply With Quote
  #5  
Old 03-30-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
sed -n '10,15p' filename

or

perl -ne 'print if 10..15' filename
Reply With Quote
  #6  
Old 03-31-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
Quote:
Originally Posted by Satadru Sen
Hi,

I have a similar problem.I want to display few lines say from line 10 to 15th in a 60 line file.The above command is not taking more than one address so suitable to display one line only.Can you help me.
Thanks,
provided link - food for thought
Reply With Quote
  #7  
Old 03-31-2006
Registered User
 

Join Date: Mar 2006
Posts: 2
Thanks friends.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:29 PM.


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

Content Relevant URLs by vBSEO 3.2.0