Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .