Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > removeing first 3 columns from the lines in file

Reply
Thread Tools

removeing first 3 columns from the lines in file

 
 
ajay
Guest
Posts: n/a
 
      02-23-2004
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
 
Reply With Quote
 
 
 
 
Sam Holden
Guest
Posts: n/a
 
      02-23-2004
On 22 Feb 2004 20:45:17 -0800, ajay <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
ajay
Guest
Posts: n/a
 
      02-23-2004
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 <(E-Mail Removed)> 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

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      02-23-2004
ajay <(E-Mail Removed)> 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]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open file, get first line, delete first line close file Richard Schneeman Ruby 16 08-26-2008 11:54 PM
ow can i use fgets to read and ignore the first two lines of a file and output into another file Justme C Programming 9 10-01-2006 02:26 PM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
removeing html from a text string Brian Henry ASP .Net 1 10-15-2003 09:48 AM
Re: how to read 10 lines from a 200 lines file and write to a new file?? Joe Wright C Programming 0 07-27-2003 08:50 PM



Advertisments