[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: matching exact lines in files

From: Alan Curry
Subject: Re: matching exact lines in files
Date: Wed, 4 Oct 2006 18:55:22 +0000 (UTC)

In article <ftOUg.4846$>,
Jim Showalter  <> wrote:
>Specifically, I want is to find all lines in a.txt that match any of

So far, this sounds like a grep.

>the following three groups of lines in b.txt:
>[Event "ICC"]

>[Event "ICC"]
>should not match because there is an intervening blank line.

Oh, a multi-line pattern. This does what you asked for:

perl -nle 'print "$prev\n$_" if $prev =~ m@^(1-0|0-1|1/2-1/2)$@ &&
                                $_ eq q/[Event "ICC"]/; $prev=$_' file

>Also, if anyone knows how I can accomplish this easily with vim, that
>would even be better.  But I have never been able to figure out how
>to include end-of-lines or blank-lines in vim searches.

I can search for newlines just fine with vim, using \n.

>Or maybe I have to use some other tools?

If I can guess your intent (rather than just giving you exactly what you
asked for), these are probably what you really want:

# Find all lines that exactly match [Event "ICC"] and print them, together
# with 1 preceding line.
grep -B 1 -Fx '[Event "ICC"]' file

# Same thing, then get rid of the [Event "ICC"] lines and the separators
# leaving only the lines that preceded the [Event "ICC"] lines
grep -B 1 -Fx '[Event "ICC"]' file |
  grep -Fxv -e '[Event "ICC"]' -e '--'

# Building on the previous example, group and count the occurrences of each
# result
grep -B 1 -Fx '[Event "ICC"]' file |
  grep -Fxv -e '[Event "ICC"]' -e '--' | sort | uniq -c

The attacker\x92s overall goal would very probably be to convince other users
to run an unsafe program, by using the digital signature to convince them
that it is actually bona fide Microsoft software and therefore safe to run.
            -- security bulletin MS01-017 ushers in a new definition of "safe"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]