<?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 question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066710#M139799</link>
    <description>All these don't cover the situation where the line printed would also match the patter, and thus should print the line after that.&lt;BR /&gt;&lt;BR /&gt;# perl -ne'BEGIN{$p=shift;$p/qr/$p/;$x=&amp;lt;&amp;gt;}$x=~$p&amp;amp;&amp;amp;print;$x=$_' pattern file&lt;BR /&gt;&lt;BR /&gt;d3:/tmp 115 &amp;gt; cat xx&lt;BR /&gt;Blah&lt;BR /&gt;Foo&lt;BR /&gt;Bar&lt;BR /&gt;Zap&lt;BR /&gt;Flunky&lt;BR /&gt;Boomer&lt;BR /&gt;Trip&lt;BR /&gt;Yoh!&lt;BR /&gt;Bzzt&lt;BR /&gt;Ahh&lt;BR /&gt;Aak&lt;BR /&gt;d3:/tmp 116 &amp;gt; perl -ne'BEGIN{$p=shift;$p/qr/$p/;$x=&amp;lt;&amp;gt;}$x=~$p&amp;amp;&amp;amp;print;$x=$_' a xx&lt;BR /&gt;Foo&lt;BR /&gt;Zap&lt;BR /&gt;Flunky&lt;BR /&gt;d3:/tmp 117 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
    <pubDate>Tue, 09 Sep 2003 13:07:52 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2003-09-09T13:07:52Z</dc:date>
    <item>
      <title>grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066704#M139793</link>
      <description>Is it possible to print out the line after the pattern found by grep.&lt;BR /&gt;&lt;BR /&gt;i.e. grep x rc.log and print out the line after x (assuming x is terminated by a new line) ?</description>
      <pubDate>Tue, 09 Sep 2003 12:11:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066704#M139793</guid>
      <dc:creator>Jeff Picton</dc:creator>
      <dc:date>2003-09-09T12:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066705#M139794</link>
      <description>Jeff,&lt;BR /&gt;&lt;BR /&gt;You can do this sort of thing with sed:&lt;BR /&gt;&lt;BR /&gt;# print 1 line of context before and after regexp, with line number&lt;BR /&gt; # indicating where the regexp occurred (similar to "grep -A1 -B1")&lt;BR /&gt; sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I'm attaching the Handy One-Liners For Sed where I swiped that from.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Sep 2003 12:17:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066705#M139794</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2003-09-09T12:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066706#M139795</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Better to use awk:&lt;BR /&gt;&lt;BR /&gt; awk '/DEVICE/ { getline a ; print a }' file_name</description>
      <pubDate>Tue, 09 Sep 2003 12:22:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066706#M139795</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2003-09-09T12:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066707#M139796</link>
      <description>try to use sed:&lt;BR /&gt;# more rc.log | sed -n '/x/{n;p;}';&lt;BR /&gt;&lt;BR /&gt;where:&lt;BR /&gt;"n" - replace the pattern space with the Next line of input&lt;BR /&gt;"p" - Print the pattern space&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Sergejs</description>
      <pubDate>Tue, 09 Sep 2003 12:49:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066707#M139796</guid>
      <dc:creator>Sergejs Svitnevs</dc:creator>
      <dc:date>2003-09-09T12:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066708#M139797</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;you can make a small script where $1 is the string to search for and $2 is the file to search in:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;grep -n "$1" "$2"| while read LINE&lt;BR /&gt;do&lt;BR /&gt;        LINE_NO=$(echo $LINE | awk -F: '{print $1}')&lt;BR /&gt;        head -$(($LINE_NO + 1)) $2 | tail -1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Sep 2003 12:55:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066708#M139797</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-09-09T12:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066709#M139798</link>
      <description>On a different but related subject (if that means sense) how do I subtract two date values of the format 12:00:27 - 12:00:00 ?</description>
      <pubDate>Tue, 09 Sep 2003 13:01:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066709#M139798</guid>
      <dc:creator>Jeff Picton</dc:creator>
      <dc:date>2003-09-09T13:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066710#M139799</link>
      <description>All these don't cover the situation where the line printed would also match the patter, and thus should print the line after that.&lt;BR /&gt;&lt;BR /&gt;# perl -ne'BEGIN{$p=shift;$p/qr/$p/;$x=&amp;lt;&amp;gt;}$x=~$p&amp;amp;&amp;amp;print;$x=$_' pattern file&lt;BR /&gt;&lt;BR /&gt;d3:/tmp 115 &amp;gt; cat xx&lt;BR /&gt;Blah&lt;BR /&gt;Foo&lt;BR /&gt;Bar&lt;BR /&gt;Zap&lt;BR /&gt;Flunky&lt;BR /&gt;Boomer&lt;BR /&gt;Trip&lt;BR /&gt;Yoh!&lt;BR /&gt;Bzzt&lt;BR /&gt;Ahh&lt;BR /&gt;Aak&lt;BR /&gt;d3:/tmp 116 &amp;gt; perl -ne'BEGIN{$p=shift;$p/qr/$p/;$x=&amp;lt;&amp;gt;}$x=~$p&amp;amp;&amp;amp;print;$x=$_' a xx&lt;BR /&gt;Foo&lt;BR /&gt;Zap&lt;BR /&gt;Flunky&lt;BR /&gt;d3:/tmp 117 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
      <pubDate>Tue, 09 Sep 2003 13:07:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066710#M139799</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-09-09T13:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066711#M139800</link>
      <description>Fetch A.Clay's just updated date Hammer from my &lt;A href="https://www.beepz.com/personal/merijn/" target="_blank"&gt;https://www.beepz.com/personal/merijn/&lt;/A&gt; or &lt;A href="http://www.cmve.net/~merijn/" target="_blank"&gt;http://www.cmve.net/~merijn/&lt;/A&gt; or use perl's modules -MDate::Calc or -MDate::Manip&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
      <pubDate>Tue, 09 Sep 2003 13:32:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066711#M139800</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-09-09T13:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066712#M139801</link>
      <description>A simple example (script also attached):&lt;BR /&gt;&lt;BR /&gt;a5:/pro/3gl/CPAN 102 &amp;gt; elapsed.pl -?&lt;BR /&gt;usage: elapsed stamp1 stamp2date/time date/time&lt;BR /&gt;       a stamp is one of date (YYYYMMDD), a time (HH:MM:SS)&lt;BR /&gt;       or a combination of both (date first).&lt;BR /&gt;       both stamps should be declared the same&lt;BR /&gt;a5:/pro/3gl/CPAN 103 &amp;gt; elapsed.pl 20:30:40 21:32:43&lt;BR /&gt;Elapsed time: 1 hour(s) 2 minute(s) 3 second(s)&lt;BR /&gt;a5:/pro/3gl/CPAN 104 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;a5:/pro/3gl/CPAN 104 &amp;gt; cat elapsed.pl&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;&lt;BR /&gt;use Date::Calc qw(Delta_DHMS);&lt;BR /&gt;&lt;BR /&gt;sub usage ()&lt;BR /&gt;{&lt;BR /&gt;    print STDERR "usage: elapsed stamp1 stamp2date/time date/time\n",&lt;BR /&gt;                 "       a stamp is one of date (YYYYMMDD), a time (HH:MM:SS)\n"&lt;BR /&gt;,&lt;BR /&gt;                 "       or a combination of both (date first).\n",&lt;BR /&gt;                 "       both stamps should be declared the same\n";&lt;BR /&gt;    exit 0;&lt;BR /&gt;    } # usage&lt;BR /&gt;&lt;BR /&gt;@ARGV == 1 and $ARGV[0] eq "-?" || $ARGV[0] =~ m/^-+help$/ and usage;&lt;BR /&gt;&lt;BR /&gt;@ARGV == 2 || @ARGV == 4 or usage;&lt;BR /&gt;&lt;BR /&gt;my %d = (y1 =&amp;gt; 2002, m1 =&amp;gt; 1, d1 =&amp;gt; 1, H1 =&amp;gt; 12, M1 =&amp;gt; 0, S1 =&amp;gt; 0,&lt;BR /&gt;         y2 =&amp;gt; 2002, m2 =&amp;gt; 1, d2 =&amp;gt; 1, H2 =&amp;gt; 12, M2 =&amp;gt; 0, S2 =&amp;gt; 0);&lt;BR /&gt;&lt;BR /&gt;if ($ARGV[0] =~ m/^(\d{4})(\d\d)(\d\d)/) {&lt;BR /&gt;    @d{qw(y1 m1 d1)} = ($1, $2, $3);&lt;BR /&gt;    shift;&lt;BR /&gt;    if (@ARGV &amp;gt; 2) {&lt;BR /&gt;        @d{qw(H1 M1 S1)} = split m/\D/, shift;&lt;BR /&gt;        defined $d{S1} or usage;&lt;BR /&gt;        }&lt;BR /&gt;    @d{qw(y2 m2 d2)} = (shift (@ARGV) =~ m/^(\d{4})(\d\d)(\d\d)/);&lt;BR /&gt;    defined $d{d2} or usage;&lt;BR /&gt;    if (@ARGV) {&lt;BR /&gt;        @d{qw(H2 M2 S2)} = split m/\D/, shift;&lt;BR /&gt;        defined $d{S2} or usage;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;else {&lt;BR /&gt;    @d{qw(H1 M1 S1)} = split m/\D/, shift;&lt;BR /&gt;    defined $d{S1} or usage;&lt;BR /&gt;    @d{qw(H2 M2 S2)} = split m/\D/, shift;&lt;BR /&gt;    defined $d{S2} or usage;&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;my ($d, $h, $m, $s) = Delta_DHMS (@d{qw(y1 m1 d1 H1 M1 S1 y2 m2 d2 H2 M2 S2)});&lt;BR /&gt;print "Elapsed time:";&lt;BR /&gt;$d             and print " $d day(s)";&lt;BR /&gt;$d || $h       and print " $h hour(s)";&lt;BR /&gt;$d || $h || $m and print " $m minute(s)";&lt;BR /&gt;                   print " $s second(s)\n";&lt;BR /&gt;a5:/pro/3gl/CPAN 105 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
      <pubDate>Tue, 09 Sep 2003 13:35:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066712#M139801</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-09-09T13:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066713#M139802</link>
      <description>Jeff,&lt;BR /&gt;&lt;BR /&gt;This may or may not help, but a long long time ago in a place far far away there was this group that collected and cataloged experimental Unix tools into a package called "exptools". Some of these commands never made it into the main stream releases of Unix. There was one command named "cgrep", it would allow you to, among other things, cgrep for a pattern and either printout lines before the match, after the match or both. i.e&lt;BR /&gt;cgrep +2 abc file1&lt;BR /&gt;would give you the line with 'abc' and the next two lines.&lt;BR /&gt;cgrep -2 abc file1&lt;BR /&gt;would give you the two lines before the match as well as the match.&lt;BR /&gt;&lt;BR /&gt;Th unfortunate thing is exptools is proprietary, unless you're an AT&amp;amp;T or Lucent employee, you can't get them.&lt;BR /&gt;&lt;BR /&gt;The good news is after doing a search on the internet it appears there is a Perl version named apptly cgrep.pl. I haven't tried it so I couldn't say how it works, but I have used and continue to use cgrep and it has been a time saver over having to come up with scripts like the ones listed above, guess I'm basically lazy.&lt;BR /&gt;&lt;BR /&gt;later,&lt;BR /&gt;&lt;BR /&gt;bob</description>
      <pubDate>Tue, 09 Sep 2003 17:58:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066713#M139802</guid>
      <dc:creator>Robert Salter</dc:creator>
      <dc:date>2003-09-09T17:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066714#M139803</link>
      <description>Hi,&lt;BR /&gt;Just a completition to my previous reply. As procura points out my simple awk example don't work if there is repeting lines with the matching pattern. This problem can be solved with a recursive function. Write a small script "test.awk" (it is more readable then writing everything on the command line). Call the script with "awk -f test.awk &lt;FILE_NAME&gt;. Change the matching pattern "DEVICE" to anything you want.&lt;BR /&gt;&lt;BR /&gt;function aaa()&lt;BR /&gt;{&lt;BR /&gt; getline x&lt;BR /&gt; if (x ~ /DEVICE/)&lt;BR /&gt;  aaa()&lt;BR /&gt; else&lt;BR /&gt;  print x&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/DEVICE/ { aaa() }&lt;BR /&gt;&lt;/FILE_NAME&gt;</description>
      <pubDate>Tue, 09 Sep 2003 18:55:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066714#M139803</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2003-09-09T18:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066715#M139804</link>
      <description>Whay all that when you can do it as follows.&lt;BR /&gt;&lt;BR /&gt;nl file_name|grep "string"</description>
      <pubDate>Wed, 10 Sep 2003 04:20:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066715#M139804</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2003-09-10T04:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066716#M139805</link>
      <description>Hi all&lt;BR /&gt;&lt;BR /&gt;Thanks all, I think i've got enough now to work on my problem.&lt;BR /&gt;&lt;BR /&gt;Jeff</description>
      <pubDate>Wed, 10 Sep 2003 07:43:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066716#M139805</guid>
      <dc:creator>Jeff Picton</dc:creator>
      <dc:date>2003-09-10T07:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066717#M139806</link>
      <description>I don't know of a way to do this with grep, but it's easy (if ugly) with awk:&lt;BR /&gt;&lt;BR /&gt;awk '/x/ {getline;print;}' rc.log&lt;BR /&gt;&lt;BR /&gt;So, the single quotes control the shell's treatment of special characters, then the forward slashes around the "x" mean find it. The curly braces are required around a block of executable lines. Having found the line with "x" in it, getline will skip to the next line, and print will print it. Semicolons end the executable line.&lt;BR /&gt;&lt;BR /&gt;Hope that helps.</description>
      <pubDate>Wed, 10 Sep 2003 12:49:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3066717#M139806</guid>
      <dc:creator>Jamie Harre</dc:creator>
      <dc:date>2003-09-10T12:49:30Z</dc:date>
    </item>
  </channel>
</rss>

