Deleting some lines from a log file

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting some lines from a log file

Eddine-2
Hi

I have to clean up a log file.
I want to exclude/delete lines that start with a number or "MPRINT" :


ENTRY

184
185  *----------------------------------------------------------------------------------------*;
186  *   PGMs Complexes               1 : enable - O : disable
                       *;
187  *----------------------------------------------------------------------------------------*;123

188
189       %include "&pgm.MainComplex.sas"    ; ** Macro principale
Base et Queries **;
NOTE: %INCLUDE (level 1) file E:\IFM
      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas
is file E:\IFM
      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas.

269 +*----------------------------------------------------------------------------------------*;
MPRINT(MAINCOMPLEX):
*----------------------------------------------------------------------------------------*;



RESULT :

NOTE: %INCLUDE (level 1) file E:\IFM
      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas
is file E:\IFM
      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas.

*----------------------------------------------------------------------------------------*;


I first tyred to identify all numbers at a beginning of a line, but
for instance when doing a substitution I cannot find the good regex
(for a try :%s/^[0-9]*/TEST/ didn't work).

Can you tell me how I have to do to delete those lines beginning by
numbers or MPRINT from my file ?

Many thanks.

Eddine.
Reply | Threaded
Open this post in threaded view
|

Re: Deleting some lines from a log file

Tom Whittock
:g/^MPRINT/d
:g/^\d\+/d

should do more or less what you want.

Cheers.

On 27/03/07, Eddine <[hidden email]> wrote:

> Hi
>
> I have to clean up a log file.
> I want to exclude/delete lines that start with a number or "MPRINT" :
>
>
> ENTRY
>
> 184
> 185  *----------------------------------------------------------------------------------------*;
> 186  *   PGMs Complexes               1 : enable - O : disable
>                        *;
> 187  *----------------------------------------------------------------------------------------*;123
>
> 188
> 189       %include "&pgm.MainComplex.sas"    ; ** Macro principale
> Base et Queries **;
> NOTE: %INCLUDE (level 1) file E:\IFM
>       2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas
> is file E:\IFM
>       2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas.
>
> 269 +*----------------------------------------------------------------------------------------*;
> MPRINT(MAINCOMPLEX):
> *----------------------------------------------------------------------------------------*;
>
>
>
> RESULT :
>
> NOTE: %INCLUDE (level 1) file E:\IFM
>       2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas
> is file E:\IFM
>       2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas.
>
> *----------------------------------------------------------------------------------------*;
>
>
> I first tyred to identify all numbers at a beginning of a line, but
> for instance when doing a substitution I cannot find the good regex
> (for a try :%s/^[0-9]*/TEST/ didn't work).
>
> Can you tell me how I have to do to delete those lines beginning by
> numbers or MPRINT from my file ?
>
> Many thanks.
>
> Eddine.
>
Reply | Threaded
Open this post in threaded view
|

Re: Deleting some lines from a log file

Tim Chase-2
In reply to this post by Eddine-2
> Can you tell me how I have to do to delete those lines beginning by
> numbers or MPRINT from my file ?

Though I'm not sure I followed your examples, if this is all you
want, the following should do what your above-summary describes:

  :g/^\(\d\|MPRINT\)/d

That breaks down as

:g/.../     on every line matching the "..." pattern
d           delete that line

The "..." of "^\(\d\|MPRINT\)" means "at the beginning of the
line (^) match either a digit (\d) or (\|) the text MPRINT" (the
"\(" and "\)" are for grouping control as I never remember
whether the beginning-of-line associates with a branch or not, so
I tend to be explicit).

Hope this helps,

-tim


Reply | Threaded
Open this post in threaded view
|

Re: Deleting some lines from a log file

Eddine-2
In reply to this post by Tom Whittock
Afterwards It seems so simple with your help
Many thanks  to you Tom, Tim and Vim community !

Eddine

2007/3/27, Tom Whittock <[hidden email]>:
> :g/^MPRINT/d
> :g/^\d\+/d
>
> should do more or less what you want.
>
> Cheers.
>
Reply | Threaded
Open this post in threaded view
|

Re: Deleting some lines from a log file

Muskoka Auto Parts Limited
In reply to this post by Eddine-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 27-Mar-07, at 9:01 AM, Eddine wrote:

> Hi
>
> I have to clean up a log file.
> I want to exclude/delete lines that start with a number or "MPRINT" :
{snippage}
> I first tyred to identify all numbers at a beginning of a line, but
> for instance when doing a substitution I cannot find the good regex
> (for a try :%s/^[0-9]*/TEST/ didn't work).
>
> Can you tell me how I have to do to delete those lines beginning by
> numbers or MPRINT from my file ?

You were close.  Try

:g/^\d\|^\(MPRINT\)/d

Using :g/regex/d to delete whole lines that contain /regex/ I find a  
lot easier than
    :%s/regex.*\n//  which accomplishes the same thing

Using \d instead of [0-9] I think is easier too.

For what it's worth,  I find it really helpful to play with regexes  
just using /regex/ and looking at the resulting highlighted areas.
Once you get just what you want you just do a :%s// or :g// and it  
fills in the last used regex.

For example - try your regex of /^[0-9]*/ then change it to /^[0-9].*/

HTH
Brian



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Verify this email or encrypt your email for free - see gnupg.org

iD8DBQFGCSTjGnOmb9xIQHQRAtLeAJ992I/JzEP+5bvAMkEoECJqBAMXGQCgmbm0
7ON4v88jNJ/rIi0/hKfOonA=
=5pm2
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Deleting some lines from a log file

Jean-Rene David-2
In reply to this post by Eddine-2
* Eddine [2007.03.27 09:45]:

> ENTRY
>
> 184
> 185  
> *----------------------------------------------------------------------------------------*;
> 186  *   PGMs Complexes               1 : enable - O : disable
>                       *;
> 187  
> *----------------------------------------------------------------------------------------*;123
>
> 188
> 189       %include "&pgm.MainComplex.sas"    ; ** Macro principale
> Base et Queries **;
> NOTE: %INCLUDE (level 1) file E:\IFM
>      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas
> is file E:\IFM
>      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas.
>
> 269
> +*----------------------------------------------------------------------------------------*;
> MPRINT(MAINCOMPLEX):
> *----------------------------------------------------------------------------------------*;
>
> RESULT :
>
> NOTE: %INCLUDE (level 1) file E:\IFM
>      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas
> is file E:\IFM
>      2005-01\gravure_2007_03_15\BRD_04-11-J\Database\Programs\MainComplex.sas.
>
> *----------------------------------------------------------------------------------------*;
>
> (for a try :%s/^[0-9]*/TEST/ didn't work).

You are close. The problem is that this pattern
will match *every* line, since you accept "zero or
more" digits at the beginning of the line.

Try:

:%s/^[0-9]\+/TEST/

Using \+ instead of * in the pattern will match
"one or more" instead of "zero or more".

Then to also match lines that begin with MPRINT:

:%s/^\([0-9]\+\|MPRINT\)/TEST/

Then to delete them (make sure you undo the
previous substitution...):

:g/^\([0-9]\+\|MPRINT\)/d

HTH,

--
JR