Ok you get the job done and got useful suggestions. Now if you want to learn more, Perl can accomplish such simple tasks in few keystrokes.

All you need to process one or more files at once is the following oneliner (caution to windows doublequotes):

perl -lane "shift @F;print qq(@F)" filename.ext

I suggest you to read perlrun where the four Perl switches -l -a -n -e are explained: in breif -l do the rigth thing with line ending, -a does autosplit of the current line filling the special variable @F (F for fields) (see perlvar too), -n wrap the whole code into a while loop without printing each line (as opposed to -p that prints) and finally -e executes the perl code provided.

You can use the core module Deparse to see the oneliner exploded (see also B::Deparse vs. O=Deparse). I added some,I hope useful, comments:

perl -MO=Deparse -lane "shift @F;print qq(@F)" # the BEGIN block is executed as soon as possible,so is not repe +ted at every iteration over file's lines # input and output record separator set by -l see again perlvar BEGIN { $/ = "\n"; $\ = "\n"; } # the while loop created by -n (do not consider the LINE: label +for the moment) LINE: while (defined($_ = <ARGV>)) { # remove newline at the end of current string (again provided by + -l) chomp $_; # autosplit provided by -a our(@F) = split(' ', $_, 0); # our program starts here shift @F; print "@F"; } -e syntax OK

HtH

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Remove the first word for each lines from a text file -- oneliner explained by Discipulus
in thread Remove the first word for each lines from a text file by ArifS

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.