Listing specific lines from a file

Listing specific lines from a file

Post by PR » Thu, 07 Dec 2000 04:00:00



Hi!
I know this may sound like a stupid newbie question, but is it possible
to list specific lines from a text file (for example, lines 10-15
etc.), or to save specific lines from a file into another file; similar
to using head and tail commands except for any desired lines from "the
middle" of a file?

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Listing specific lines from a file

Post by Ronn » Thu, 07 Dec 2000 04:00:00




Quote:> I know this may sound like a stupid newbie question, but is it
possible
> to list specific lines from a text file (for example, lines 10-15
> etc.), or to save specific lines from a file into another file;
similar
> to using head and tail commands except for any desired lines from "the
> middle" of a file?

sed -n 10,15p <FILE

--

http://profiles.yahoo.com/ronny_fischer/

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Listing specific lines from a file

Post by Tristan Quaif » Thu, 07 Dec 2000 04:00:00



> Hi!
> I know this may sound like a stupid newbie question, but is it possible
> to list specific lines from a text file (for example, lines 10-15
> etc.), or to save specific lines from a file into another file; similar
> to using head and tail commands except for any desired lines from "the
> middle" of a file?

You _could_ use head and tail.
e.g. to get line 10-15 from file.txt,

head -15 file.txt | tail -6

Personally I'd use gawk:

gawk 'NR>=10&&NR<=15' file.txt

Hope this helps,

Tristan.

 
 
 

Listing specific lines from a file

Post by Al A » Fri, 08 Dec 2000 04:00:00


                        sed "2,4!d" in > out
--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, ex seders moderator                                   sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

 
 
 

Listing specific lines from a file

Post by Jim Britai » Mon, 11 Dec 2000 21:31:45



>                    sed "2,4!d" in > out

Well, that doesn't work worth a damn.  How about:

sed -n '2,4p' filename

 
 
 

Listing specific lines from a file

Post by Otavio Ex » Tue, 12 Dec 2000 10:47:48



> Well, that doesn't work worth a damn.  How about:

> sed -n '2,4p' filename

this..

        sed -e '1d' -e '4q'

..would do the same without reading the whole (possibly *BIG*) file;

beers,

--