Hello monks,
Hope this is a simple thing. Tried to search but couldn't find a reasonable solution for the same.
What I want is to print line number say 60 to 70 in a file.

This will work out using sed
sed -n '60,70 p' wordlist
Simply using head,tail it will work out
tail -n +60 wordlist|head -10
Using perl $. it will work out
perl -ne 'print if $. ~~ [60..70]' wordlist
Using perl list context, it works out.
perl -e 'my @lines=`cat wordlist`;print @lines[60..70];'

What I want is any way we can eliminate that @lines array and do it in one line. Tried somethings but can't make it out. e.g.
perl -e 'print @(`cat wordlist`)[60..70];'

Or
perl -e 'print (@(`cat wordlist`))[60..70];'

But nothing works out. Would be thankful if you could help me in that.

In reply to Reading specific lines in a file by gurpreetsingh13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.