Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: extract (a range of) numbered lines from a file

by shmem (Chancellor)
on Sep 21, 2016 at 17:45 UTC ( [id://1172317]=note: print w/replies, xml ) Need Help??


in reply to Re: extract (a range of) numbered lines from a file
in thread extract (a range of) numbered lines from a file

somefile shouldn't be there, right?

Right. And I completely forgot about -n which eliminates the call to awk ;-) So all that's necesary is:

sed -ne '10,15p;5p' file
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^3: extract (a range of) numbered lines from a file
by choroba (Cardinal) on Sep 21, 2016 at 18:31 UTC
    No, that's not the same. It still outputs the empty lines.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Well, mine doesn't, for sure. Transcript:

      qwurx [shmem] ~> perl -le 'print "line $_" for 1..15' >| linenumber.tx +t qwurx [shmem] ~> sed -ne '10,15p;5p' linenumber.txt line 5 line 10 line 11 line 12 line 13 line 14 line 15 qwurx [shmem] ~> which sed /bin/sed qwurx [shmem] ~> dpkg -S `which sed` sed: /bin/sed qwurx [shmem] ~> dpkg -l sed Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/T +rig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-===============-============-============-======================== +============ ii sed 4.2.2-4+b1 amd64 The GNU sed stream edito +r

      Show evidence of yours.

      In defence of my oh-so-cool perl snippet -

      • l is less typing than sed -ne
      • on subsequent calls with the same file, I need not specify the file as argument
      • it is the one script which needed a CHECK block

      And that's pretty much all about that. If I were better at typing, two of them three arguments would be quite pointless ;-)

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        There are no empty lines in your input.
        21:30 choroba@still ~ $ perl -E 'say "\n", 2 * $_ for 1 .. 10' | sed - +ne '10,15p;5p' 10 12 14 21:31 choroba@still ~ $ perl -E 'say "\n", 2 * $_ for 1 .. 10' | sed - +ne '/^$/d;10,15p;5p' 10 12 14 21:31 choroba@still ~ $ type sed sed is /bin/sed 21:31 choroba@still ~ $ rpm -q sed sed-4.2.2-5.1.2.x86_64

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-26 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found