Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a grep-like command that outputs full records instead of a fixed number of context lines.

For instance:

grep -d record_delimiter PATTERN [FILE]

Logic:

  • split the FILE in records according to the record_delimiter.
  • If a match is found, print the whole record and skip to the next one
share|improve this question

2 Answers 2

up vote 1 down vote accepted

Use awk and change the record separator RS, like this:

awk -v RS= '/PATTERN/ { print $0"\n" }' [FILE]

share|improve this answer

You can also check out Recutils, which offers some pretty robust, database-like options for querying and manipulating files of records.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.