Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by choroba (Cardinal)
on Sep 21, 2016 at 18:31 UTC ( [id://1172322]=note: print w/replies, xml ) Need Help??


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

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,

Replies are listed 'Best First'.
Re^4: extract (a range of) numbered lines from a file
by shmem (Chancellor) on Sep 21, 2016 at 18:53 UTC

    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,
        There are no empty lines in your input.

        Ah, I see now. Eliminating empty lines was not a requirement, although the OP wasn't clear about that, since the convoluted sed | awk construct in fact did remove all empty lines, even those wanted. The perl script doesn't, however. The sed | awk was there for illustration purposes alone.

        The l script is meant to include empty lines of input. Sorry for the unclear spec.

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found