grep
is acting like it should in default mode. From its man
page:
...grep searches for PATTERNS in each FILE. PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern...
So, it's supposed to turn up lines in the text matching a regex
. Lines are demarcated by the newline
control code, which explains the behavior you are seeing. Other than using the -z
option mentioned in the responses. Assuming "issue" is the regex you want to match (replace with 'Device Degraded'
or '\sDegraded'
or '\sError'
if that's what you are actually looking to match); and that the "Corrective Action" column is machine generated and consistent, i.e., always spanning 4 lines you could also simply just run grep -A 3 '\sissue' > issues
to save only the lines you are interested in into a file. You must be able to generate output which looks like:
1 ok device issue Some Action which has to be taken which is split into many lines under d. -- 10 ok device issue Some Action which has to be taken which is split into may lines under d. -- 211 ok device issue Some Action which has to be taken which is split into many lines under d.
check grep's man page to find out more about what these options do.
d
is multiple lines.grep
is working in the way that it's designed.awk
will do the same thing if you use it to search forissue
and then print. Your only option is to maked
one line.awk
in a way to match the whole column if you reassign Record Separator and Field Separator.grep -E 'issue|^
, or useperl
.