When I compile my VHDL design I get a large log file which I want to filter.
Is it possible to do this?
I was wondering to search for certain patterns in the log file and
provide a start and end mark for the interresting stuff.
And then delete all that isn't in the selected sections.
Is that possible?
For example, if the text is this:
+--- START OF LOG ---+
[...]
Not interesting stuff.
[...]
AAA ... BBB ... CCC
[...]
Interesting stuff.
[...]
DDD .... EEE
[...]
Not interesting stuff.
[...]
FFF
[...]
Interesting stuff.
[...]
GGG ... HHH
[...]
Not interesting stuff.
[...]
KKK ... LLL ... MMM ... NNN
[...]
Interesting stuff.
[...]
PPP ... QQQ ... RRR
+--- END OF LOG ---+
1) Can you then search for a pattern that starts with AAA and then
followed by BBB and ending with CCC and place a start mark to select
the line
AAA ... BBB ... CCC
(... means any kind of text, but not AAA, BBB or CCC)
2) And then place an end mark at the line
DDD .... EEE
3) Do the same for FFF (place here a start mark) and GGG ... HHH
(place an end mark)
4) Do the same for KKK ... LLL ... MMM ... NNN (place a start mark)
and PPP ... QQQ ... RRR (place an end mark)
5) Now you have a log file with start and ending marks. How to delete
the selection that are not in the start and ending marks?
Or if that's easier, how to copy the sections marked to a new file?
So that the new log file is as:
+--- START OF LOG ---+
AAA ... BBB ... CCC
[...]
Interesting stuff.
[...]
DDD .... EEE
FFF
[...]
Interesting stuff.
[...]
GGG ... HHH
KKK ... LLL ... MMM ... NNN
[...]
Interesting stuff.
[...]
PPP ... QQQ ... RRR
+--- END OF LOG ---+
Rgds,
Jeri
While it's a little hard to determine the particulars from your
description and pseudo-examples, the general process I use to do
something similar looks like
:g/interesting/sil! ?start?,/end/s/^/XXX/
:v/^XXX/d
:%s/^XXX
This searches for every line matching the pattern "interesting",
then searches backwards for the pattern "start" as the beginning
of the range, and forward to the pattern "end". With each of
those start...end ranges, it tacks on a unique prefix (in this
case, "XXX") The "sil!" is just to prevent it from reporting
action on every matching line because it annoys me :)
Now that you've found and marked the interesting stuff, you can
delete the rest (the "v/^XXX/d").
Finally, remove the "XXX" marker leaving you with just what you want.
Each of those patterns can be an arbitrary regexp, so you can use
multiple conditions:
:g/foo\|bar\|baz/sil! ...
Alternatively, I'll use ">" as my command instead of "s/^/XXX" to
indent the lines of interest (best done with 'noet' and 'sw'='ts'
so you get one tab of indent), delete the non-indented lines, and
then un-indent the indented lines:
:g/interesting/sil! ?start?,/end/>
:v/^\t/d
:%<
Hope this gives you a general pattern you can use.
-tim
(Rearranged to trimmed inline-quoting rather than top-posting, as
is preferred on the mailing-list)
Yes, you can give other relative ranges. Note that it breaks down as
:g/pattern/action_to_perform_on_matching_lines
where action happens to be
<range>s/foo/bar/
(prefixed with "sil!" as previously detailed) and where <range>
happens to be "search backwards for pattern A, through searching
forwards to pattern B". For the line above/below version, you
could just change the range from the complex searches to
".-1,.+1" or more tersely, "-,+" as searches are relative to the
current line (the line found by each :g hit) so the "." is
optional, and adding/subtracting lines defaults to 1 if omitted.
:help :range
That would make the command
:g/interesting/sil! .-1,.+1s/^/XXX
or
:g/interesting/sil! -,+s/^/XXX
To adjust the number of lines of context, just change the "-1" to
however many lines you want before, and the "+1" to however many
lines you want after.
Note that you might hit a fence-posting case if the last
"interesting" match, plus whatever forward-context you want (in
this case, one line; in the previous case, searching forward to a
pattern) puts you beyond the end-of-file. So you might want to
hand-verify the final "interesting" match in the file.
-tim
Oh, I missed the paragraph bits...if they're blank-line separated
paragraphs, you can use the range '{,'} as in
g/interesting/sil! '{,'}s/^/XXX
You can read about those marks at
:help '{
:help '}
-tim