Re: matching exact lines in files

Jim Showalter <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization ComputeC
Message-ID <[email protected]>
Alan Curry wrote:

> In article <[email protected]>,
>
> I can search for newlines just fine with vim, using \n.
>

Well I'll be... that works - thanks!

>
> 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
>

Well, you didn't quite guess my intent.  I just want to find cases
where there is no intervening blank line and insert one.

If we find this:

1-0
[Event "ICC"]

We change it to this:

1-0

[Event "ICC"]

Thanks much,
jim
--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/  Everything should be made as simple as possible, but not simpler.
_/                           -- Albert Einstein
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.