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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-20-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 Unix and Linux 09-20-2005
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 5 March 2015, 4:35 AM EST
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts

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

vino

Last edited by vino; 09-20-2005 at 12:41 AM..
Sponsored Links
    #3  
Old Unix and Linux 09-20-2005
RishiPahuja's Unix or Linux Image
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 Unix and Linux 09-20-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 5 July 2014, 11:14 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 Unix and Linux 09-20-2005
blowtorch's Unix or Linux Image
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 28 July 2014, 9:39 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 Unix and Linux 09-20-2005
zazzybob's Unix or Linux Image
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 Unix or Linux Image


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

Cheers
ZB
Sponsored Links
    #7  
Old Unix and Linux 09-20-2005
reborg's Unix or Linux Image
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 11 Times in 11 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 12:12 PM.. Reason: fix the tags
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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-24-2011 12:44 AM
grep and display lines from a file user7617 Shell Programming and Scripting 6 08-28-2009 12:41 AM
Display file without # lines dave123 Shell Programming and Scripting 5 06-28-2008 01:22 PM
Display lines of the file on a log sbryant Shell Programming and Scripting 2 02-26-2008 02:16 PM
display few lines of the file sharuvman UNIX for Dummies Questions & Answers 4 04-27-2004 08:14 AM



All times are GMT -4. The time now is 04:12 PM.