display a portion of lines from file | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

display a portion of lines from file

UNIX for Dummies Questions & Answers


Tags
grep or

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-19-2005
champion champion is offline
Registered User
 
Join Date: Jul 2002
Last Activity: 15 November 2005, 5:10 AM EST
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
display a portion of lines from file

This is truly dummy question.

I have a text file of 100 lines.

What unix commnad to extract line 20 to 40 and output it to another file?

Is it something cat or grep or >> ?

Thanks
Sponsored Links
    #2  
Old 09-19-2005
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts

Code:
sed -n '20,40p' input.file > output.file

vino

Last edited by vino; 09-19-2005 at 11:41 PM..
Sponsored Links
    #3  
Old 09-19-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 15 April 2011, 1:11 AM EDT
Location: Bangalore, India
Posts: 203
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL

sed -n '20,40p' infile > outfile
    #4  
Old 09-20-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 11 April 2014, 1:02 AM EDT
Location: classification algos
Posts: 3,203
Thanks: 19
Thanked 30 Times in 27 Posts
just another way of doing it

awk '{if (NR >= 20 && NR <= 40) print $0}' inputfile > outputfile
Sponsored Links
    #5  
Old 09-20-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 10 October 2013, 8:46 AM EDT
Location: UK
Posts: 2,351
Thanks: 0
Thanked 6 Times in 6 Posts
While we are exploring different ways of doing things:

Code:
 head -40 infile|tail -20 > outfile

Sponsored Links
    #6  
Old 09-20-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
Quote:
Originally Posted by blowtorch
While we are exploring different ways of doing things:
Indeed


Code:
perl -n -e  '( $. >= 20 && $. <= 40 ) && print ' infile > outfile

Cheers
ZB
Sponsored Links
    #7  
Old 09-20-2005
reborg's Avatar
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 10 Times in 10 Posts
Quote:
Originally Posted by matrixmadhan
just another way of doing it

awk '{if (NR >= 20 && NR <= 40) print $0}' inputfile > outputfile
or more concisely

Code:
awk 'NR >= 20 && NR <= 40' infile > outfile

or more quickly on a large file:

Code:
awk 'NR >= 20; NR == 40 {exit}' infile > outfile


Last edited by reborg; 09-20-2005 at 11:12 AM.. Reason: fix the tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to display only the lines from a file which do not contain a given number herberwz UNIX Desktop for Dummies Questions & Answers 3 06-23-2011 11:44 PM
grep and display lines from a file user7617 Shell Programming and Scripting 6 08-27-2009 11:41 PM
Display file without # lines dave123 Shell Programming and Scripting 5 06-28-2008 12:22 PM
Display lines of the file on a log sbryant Shell Programming and Scripting 2 02-26-2008 01:16 PM
display few lines of the file sharuvman UNIX for Dummies Questions & Answers 4 04-27-2004 07:14 AM



All times are GMT -4. The time now is 10:29 AM.