I have the following sed command that fetches back a whole chunk of a log that has an <interface>
XML within it that's being printed into a txt file:
sed -n '/(StartingExpression)/{:start /<\/Interface>/!{N;b start};/(SomeValueInTheXML)"/p}' *.log > File.txt
The issue is that I have some dynamic values (time stamp) that's always 4 lines above the (StartingExpression)
... is there a way to print something like:
line of (StartingExpression) -4
?
I found this question: search (e.g. awk, grep, sed) for string, then look for X lines above and another string below but the solution isn't really clear :\
Thanks for the help.
also, if anyone has a good source to learn sed, I'll be thankful if you post it :)
EDIT per request:
one
two
1/1/2015
line 1
12345
(StartingExpression)
<Interface>
<A>
Name=Andy
</A>
</Interface>
three
four
1/1/2015
line 1
12345
(StartingExpression)
<Interface>
<A>
Name=John
</A>
</Interface>
hello
world
I would like to print from 1/1/2015
(which is 3 lines above (StartingExpression)
- this can be dynamic as its a date ) until </Interface>
EDIT: I forgot to mention, there can be multiple instances of these interfaces... How do you also ensure to print ONLY the one that has Name=Andy
?
file.txt:
1/1/2015
line 1
12345
(StartingExpression)
<Interface>
<A>
Name=Andy
</A>
</Interface>