removeing first 3 columns from the lines in file

Discussion in 'Perl Misc' started by ajay, Feb 23, 2004.

  1. ajay

    ajay Guest

    In log file i have lines like this:

    01-22T09:26:24.560 [00504] (tShell) {0xd071920}
    Alcap_menu::send_establish_response] | SUCCESS

    It's single line. now i want to remove first 3 columns( better to say
    first 3 set of strings seperated by spaces) of line and retain rest of
    line, i.e I want to have only this:

    Alcap_menu::send_establish_response] | SUCCESS

    How to do it in a single perl command ?

    Tx
    ajay, Feb 23, 2004
    #1
    1. Advertising

  2. ajay

    Sam Holden Guest

    On 22 Feb 2004 20:45:17 -0800, ajay <> wrote:
    > In log file i have lines like this:
    >
    > 01-22T09:26:24.560 [00504] (tShell) {0xd071920}
    > Alcap_menu::send_establish_response] | SUCCESS
    >
    > It's single line. now i want to remove first 3 columns( better to say
    > first 3 set of strings seperated by spaces) of line and retain rest of
    > line, i.e I want to have only this:
    >
    > Alcap_menu::send_establish_response] | SUCCESS
    >
    > How to do it in a single perl command ?


    Does preserving exact whitespace matter?

    perl -lane 'print "@F[3..$#F]"'

    If it does:

    perl -pe "s/^\S+\s+\S+\s+\S+//"

    Or the now leading space should also go:

    perl -pe "s/^\S+\s+\S+\s+\S+\s+//"

    replace \s+ with ' ' or \t or whatever if the whitespace is more
    restrictively defined (which would allow \S* to be useful for empty
    fields...)

    --
    Sam Holden
    Sam Holden, Feb 23, 2004
    #2
    1. Advertising

  3. ajay

    ajay Guest

    Tx Sam it works
    This is the command which solves my purpose.

    perl -pi -e "s/^\S+\s+\S+\s+\S+\s+\S+\s+//" log_file


    Sam Holden wrote:
    >
    > On 22 Feb 2004 20:45:17 -0800, ajay <> wrote:
    > > In log file i have lines like this:
    > >
    > > 01-22T09:26:24.560 [00504] (tShell) {0xd071920}
    > > Alcap_menu::send_establish_response] | SUCCESS
    > >
    > > It's single line. now i want to remove first 3 columns( better to say
    > > first 3 set of strings seperated by spaces) of line and retain rest of
    > > line, i.e I want to have only this:
    > >
    > > Alcap_menu::send_establish_response] | SUCCESS
    > >
    > > How to do it in a single perl command ?

    >
    > Does preserving exact whitespace matter?
    >
    > perl -lane 'print "@F[3..$#F]"'
    >
    > If it does:
    >
    > perl -pe "s/^\S+\s+\S+\s+\S+//"
    >
    > Or the now leading space should also go:
    >
    > perl -pe "s/^\S+\s+\S+\s+\S+\s+//"
    >
    > replace \s+ with ' ' or \t or whatever if the whitespace is more
    > restrictively defined (which would allow \S* to be useful for empty
    > fields...)
    >
    > --
    > Sam Holden
    ajay, Feb 23, 2004
    #3
  4. ajay

    Anno Siegel Guest

    ajay <> wrote in comp.lang.perl.misc:
    > Tx Sam it works
    > This is the command which solves my purpose.
    >
    > perl -pi -e "s/^\S+\s+\S+\s+\S+\s+\S+\s+//" log_file


    (Please don't top-post)

    This is clearer, imo:

    perl -p -e '(split " ", $_, 3)[ 2]' log_file

    Anno

    [TOFU snipped]
    Anno Siegel, Feb 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry

    removeing html from a text string

    Brian Henry, Oct 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    286
    Tim Stephenson
    Oct 15, 2003
  2. Joe Wright
    Replies:
    0
    Views:
    497
    Joe Wright
    Jul 27, 2003
  3. Justme
    Replies:
    9
    Views:
    601
    clayne
    Oct 1, 2006
  4. Murali
    Replies:
    2
    Views:
    542
    Jerry Coffin
    Mar 9, 2006
  5. Richard Schneeman
    Replies:
    16
    Views:
    455
    Daniel Bush
    Aug 27, 2008
Loading...

Share This Page