<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Grep issue in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881233#M45272</link>
    <description>Mark,&lt;BR /&gt;&lt;BR /&gt;Here is the solution:&lt;BR /&gt;&lt;BR /&gt;cat &lt;OUTPUT_FILE_NAME&gt; | sed -n -e '/&lt;MATCHING_LINE&gt;/{x;1!p;g;$!N;p;D;}' -e h&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Sergejs&lt;/MATCHING_LINE&gt;&lt;/OUTPUT_FILE_NAME&gt;</description>
    <pubDate>Thu, 20 Jan 2005 12:36:15 GMT</pubDate>
    <dc:creator>Sergejs Svitnevs</dc:creator>
    <dc:date>2005-01-20T12:36:15Z</dc:date>
    <item>
      <title>Grep issue</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881230#M45269</link>
      <description>I need to grep a string from an output file, but when I get a match I also need the line above and below the matching line i.e&lt;BR /&gt;&lt;BR /&gt;lines read as follows:&lt;BR /&gt;&lt;BR /&gt;----10.70.110.18 PING Statistics----&lt;BR /&gt;2 packets transmitted, 1 packets received, 50% packet loss&lt;BR /&gt;Mon Jan 17 12:45:49 GMT 2005&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HELP!!!!!!!!!!!!!!!!</description>
      <pubDate>Thu, 20 Jan 2005 10:23:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881230#M45269</guid>
      <dc:creator>Mark Misselbrook</dc:creator>
      <dc:date>2005-01-20T10:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Grep issue</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881231#M45270</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;If you are on Linux and using the GNU grep, you can use the -B 1 option to print the line before the matching line, and the -C 1 option to print the line after.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Jan 2005 10:40:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881231#M45270</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2005-01-20T10:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: Grep issue</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881232#M45271</link>
      <description>Hi Mark, you can do it with awk like this:&lt;BR /&gt;&lt;BR /&gt;awk '/expresion/ {print prev ; print $0 ; getline ; print $0}&lt;BR /&gt;{prev=$0}' file_in&lt;BR /&gt;&lt;BR /&gt;If you want, you can create a file like this:&lt;BR /&gt;----- file.awk -----&lt;BR /&gt;/expresion/ {print prev ; print $0 ; getline ; print $0}&lt;BR /&gt;{prev=$0}&lt;BR /&gt;-------- end file.awk -----------&lt;BR /&gt;&lt;BR /&gt;Then you can type:&lt;BR /&gt;&lt;BR /&gt;awk -f file.awk file_in&lt;BR /&gt;&lt;BR /&gt;and get the same result.&lt;BR /&gt;&lt;BR /&gt;Frank.</description>
      <pubDate>Thu, 20 Jan 2005 10:44:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881232#M45271</guid>
      <dc:creator>Francisco J. Soler</dc:creator>
      <dc:date>2005-01-20T10:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Grep issue</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881233#M45272</link>
      <description>Mark,&lt;BR /&gt;&lt;BR /&gt;Here is the solution:&lt;BR /&gt;&lt;BR /&gt;cat &lt;OUTPUT_FILE_NAME&gt; | sed -n -e '/&lt;MATCHING_LINE&gt;/{x;1!p;g;$!N;p;D;}' -e h&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Sergejs&lt;/MATCHING_LINE&gt;&lt;/OUTPUT_FILE_NAME&gt;</description>
      <pubDate>Thu, 20 Jan 2005 12:36:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881233#M45272</guid>
      <dc:creator>Sergejs Svitnevs</dc:creator>
      <dc:date>2005-01-20T12:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Grep issue</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881234#M45273</link>
      <description>John was close, the -C 1 gives both the line immediately before and after the matched line.&lt;BR /&gt;&lt;BR /&gt;Here's right out of the gnu grep man page:&lt;BR /&gt;&lt;BR /&gt;OPTIONS&lt;BR /&gt;       -A NUM, --after-context=NUM     Print  NUM  lines  of  trailing  context  after  matching lines. Places  a  line  containing  --  between  contiguous  groups  of matches.&lt;BR /&gt;       -B NUM, --before-context=NUM     Print NUM  lines  of  leading  context before  matching  lines. Places  a  line  containing  --  between  contiguous  groups  of matches.&lt;BR /&gt;       -C NUM, --context=NUM     Print  NUM lines of output context.  Places a line containing -- between contiguous groups of matches.&lt;BR /&gt;&lt;BR /&gt;hope that helps,&lt;BR /&gt;&lt;BR /&gt;--Dave</description>
      <pubDate>Thu, 20 Jan 2005 19:53:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881234#M45273</guid>
      <dc:creator>Dave Falloon</dc:creator>
      <dc:date>2005-01-20T19:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Grep issue</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881235#M45274</link>
      <description>The sed solution from Sergejs worked perfectly.&lt;BR /&gt;&lt;BR /&gt;10 points</description>
      <pubDate>Fri, 21 Jan 2005 05:24:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-issue/m-p/4881235#M45274</guid>
      <dc:creator>Mark Misselbrook</dc:creator>
      <dc:date>2005-01-21T05:24:19Z</dc:date>
    </item>
  </channel>
</rss>

