Results 1 to 4 of 4

Thread: Regexp Question

  1. #1

    Default Regexp Question

    Is there a way I can build a regular expression (for grep) that will give me not only the line that matches it, but also one line before and after?

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Regexp Question

    You don't need to futz with the RE, the -A and -B options to grep do what you want, show you a specified number of lines after and before the matching line respectively.

  3. #3

    Default Re: Regexp Question

    OK, that works. Is there an option to turn off the "--" that grep adds between the matches, other than the obvious "grep -A 1 -B 1 -e '\*A/' < infile | sed '/^--$/d'"?

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Regexp Question

    Seems as good a solution as any. BTW, you don't need < infile, just infile will do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •