The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
print line whatever line i want in a file... there any way kittusri9 Shell Programming and Scripting 1 05-15-2008 09:37 AM
How to print 3rd to last line of file? NivekRaz Shell Programming and Scripting 2 09-10-2007 05:04 PM
how to print out line numbers of a text file? forevercalz Shell Programming and Scripting 4 12-12-2005 01:04 AM
Print file line by line handak9 Shell Programming and Scripting 2 10-20-2005 05:44 AM
Print one line of Existing File danhodges99 UNIX for Dummies Questions & Answers 2 02-25-2003 07:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2007
Registered User
 

Join Date: Apr 2007
Posts: 6
Stumble this Post!
how to print 35th line from a file ?

Hi All,

I am a newbie.I hope I will learn lot here.
Thanks for buliding such a resourceful forum.

My question :

I want to print just the 35th line in a file ,
how can I do it , any smallest possible script please?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-14-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Stumble this Post!
Gridview,
See if this works for you:
Code:
sed -n '35p' input_file
Reply With Quote
  #3 (permalink)  
Old 05-14-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,546
Stumble this Post!
Code:
awk 'NR == 35 { print ; exit }' filename
Reply With Quote
  #4 (permalink)  
Old 05-14-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,546
Stumble this Post!
one more,

Code:
perl -e 'while (<>) { print $_ if ($. == 35 ); }' filename
Reply With Quote
  #5 (permalink)  
Old 05-14-2007
Registered User
 

Join Date: Apr 2007
Posts: 6
Stumble this Post!
Hi Shell_Life,

Thanks for quick reply.

It worked !

could you please explain me the logic behind the implementation of the command ?
OR you can direct me to links/sources where I can read about it .



Quote:
Originally Posted by Shell_Life
Gridview,
See if this works for you:
Code:
sed -n '35p' input_file
Reply With Quote
  #6 (permalink)  
Old 05-14-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,537
Stumble this Post!
Code:
awk 'NR==35' file
Reply With Quote
  #7 (permalink)  
Old 05-14-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,546
Stumble this Post!
Quote:
Originally Posted by ghostdog74
Code:
awk 'NR==35' file

This would still continue validating even after the 'n'th line has been selected and printed. Hence IMHO exit should be used !
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:54 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