Below is the text in the file:
Pseudo name=Apple
Code=42B
state=fault
Pseudo name=Prance
Code=43B
state=good
I need to grep for "42B" and get the output from the above text like:
Pseudo name=Apple
Code=42B
state=fault
Does anyone have idea on how to achieve this using grep
/awk
/sed
?
Best Answer
With
awk
RS=
changes the input record separator from a newline to blank lines. If any field in an record contains/42B/
print the record.''
(the null string) is a magic value used to represent blank lines according to POSIX:The output paragraphs will not be separated since the output separator remains a single newline. To ensure that there is a blank line between output paragraphs, set the output record separator to two newlines: