<?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: searching script help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019837#M745673</link>
    <description>Hy&lt;BR /&gt;&lt;BR /&gt;Here is also a perl script:&lt;BR /&gt;&lt;BR /&gt;# cat testing.pl&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;my $search=shift;&lt;BR /&gt;my (@saves,@lines);&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;        if ($_ =~ /$search/) {&lt;BR /&gt;                foreach $i (0..$#saves)&lt;BR /&gt;                {&lt;BR /&gt;                        if ($saves[$i] =~ /^\d{4}-\d{1}-\d{1}/) {&lt;BR /&gt;                                unshift(@lines,$saves[$i]);&lt;BR /&gt;                                last;&lt;BR /&gt;                        } else {&lt;BR /&gt;                                push(@lines,$saves[$i]);&lt;BR /&gt;                        }&lt;BR /&gt;                }&lt;BR /&gt;&lt;BR /&gt;        push(@lines,$_);&lt;BR /&gt;&lt;BR /&gt;        if ($#lines &amp;gt; 0){&lt;BR /&gt;                foreach $i (0..$#lines)&lt;BR /&gt;                {&lt;BR /&gt;                        print $lines[$i];&lt;BR /&gt;                }&lt;BR /&gt;        }&lt;BR /&gt;                @lines = ();&lt;BR /&gt;                @saves = ();&lt;BR /&gt;        } else {&lt;BR /&gt;                unshift(@saves,$_);&lt;BR /&gt;&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;# perl testing.pl "c v f 3 4 5 6" filename&lt;BR /&gt;2006-1-3&lt;BR /&gt;a b c d e f g&lt;BR /&gt;e 1 2 g 4 5 6&lt;BR /&gt;d 1 2 3 4 5 6&lt;BR /&gt;c v f 3 4 5 6&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards</description>
    <pubDate>Wed, 20 Dec 2006 08:44:19 GMT</pubDate>
    <dc:creator>Oviwan</dc:creator>
    <dc:date>2006-12-20T08:44:19Z</dc:date>
    <item>
      <title>searching script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019833#M745669</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I've a file as follows:&lt;BR /&gt;&lt;BR /&gt;2006-1-1&lt;BR /&gt;a 1 2 3 4 5 6 &lt;BR /&gt;b 1 2 3 4 5 6 &lt;BR /&gt;c 1 2 3 4 5 6&lt;BR /&gt;d 1 2 k 4 5 6 &lt;BR /&gt;2007-1-2&lt;BR /&gt;a 1 2 g 4 5 6 &lt;BR /&gt;d 1 2 t 4 5 6&lt;BR /&gt;d 1 2 t 4 5 6&lt;BR /&gt;e 1 2 r 4 5 6 &lt;BR /&gt;2006--1-3&lt;BR /&gt;d 1 2 3 4 5 6&lt;BR /&gt;e 1 2 g 4 5 6 &lt;BR /&gt;a b c d e f g&lt;BR /&gt;c v f 3 4 5 6&lt;BR /&gt;&lt;BR /&gt;I would like to search the file to print&lt;BR /&gt;2006--1-3&lt;BR /&gt;d 1 2 3 4 5 6&lt;BR /&gt;e 0 0 0 4 5 6 &lt;BR /&gt;a b c d e f g&lt;BR /&gt;&lt;BR /&gt;based on first occurance of the input search string&lt;BR /&gt;&lt;BR /&gt;e 0 0 0 4 5 6&lt;BR /&gt;&lt;BR /&gt;ie. basically&lt;BR /&gt;on greping the first occurance of&lt;BR /&gt;e 0 0 0 4 5 6&lt;BR /&gt;&lt;BR /&gt;how can I print the previous say 20 lines,&lt;BR /&gt;or &lt;BR /&gt;how can I print the previous lines up to the header 2006&lt;BR /&gt;&lt;BR /&gt;Thanks for all help...&lt;BR /&gt;Bill</description>
      <pubDate>Wed, 20 Dec 2006 06:42:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019833#M745669</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2006-12-20T06:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: searching script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019834#M745670</link>
      <description>&lt;!--!*#--&gt;Hi Bill!&lt;BR /&gt;&lt;BR /&gt;[ Long time, no hear :-)) ]&lt;BR /&gt;&lt;BR /&gt;OK, try this Perl script:&lt;BR /&gt;&lt;BR /&gt;# cat ./findpat&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $pat = shift;&lt;BR /&gt;my @lines;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    shift @lines if $#lines &amp;gt; 20;&lt;BR /&gt;    if (/$pat/) {&lt;BR /&gt;        print for @lines;&lt;BR /&gt;        print;&lt;BR /&gt;        last;&lt;BR /&gt;    }&lt;BR /&gt;    push @lines,$_;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...Run it passing the pattern to match as the first argument and the file to process as the second:&lt;BR /&gt;&lt;BR /&gt;# ./findpat 2006--1-3 filename&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 20 Dec 2006 07:52:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019834#M745670</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-20T07:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: searching script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019835#M745671</link>
      <description>Bill,&lt;BR /&gt;&lt;BR /&gt;Here's how to print 20 lines prior to a regex using 'ex':&lt;BR /&gt;&lt;BR /&gt;$ ex -s +"g/e 0 0 0 4 5 6/-20,/e 0 0 0 4 5 6/p | q!" &amp;lt; infile&lt;BR /&gt;&lt;BR /&gt;PCS</description>
      <pubDate>Wed, 20 Dec 2006 08:01:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019835#M745671</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2006-12-20T08:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: searching script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019836#M745672</link>
      <description>Bill,&lt;BR /&gt;I'm sorry, but I don't understand the requirement.&lt;BR /&gt;e 0 0 0 4 5 6 is not in the file, so a grep would return nothing.&lt;BR /&gt;&lt;BR /&gt;Might be easiest to get gnu grep which has a -B n option, showing n lines before the matched line.&lt;BR /&gt;&lt;BR /&gt;For context grep/sed/perl solutions:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=861863" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=861863&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=793890" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=793890&lt;/A&gt;</description>
      <pubDate>Wed, 20 Dec 2006 08:11:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019836#M745672</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-12-20T08:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: searching script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019837#M745673</link>
      <description>Hy&lt;BR /&gt;&lt;BR /&gt;Here is also a perl script:&lt;BR /&gt;&lt;BR /&gt;# cat testing.pl&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;my $search=shift;&lt;BR /&gt;my (@saves,@lines);&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;        if ($_ =~ /$search/) {&lt;BR /&gt;                foreach $i (0..$#saves)&lt;BR /&gt;                {&lt;BR /&gt;                        if ($saves[$i] =~ /^\d{4}-\d{1}-\d{1}/) {&lt;BR /&gt;                                unshift(@lines,$saves[$i]);&lt;BR /&gt;                                last;&lt;BR /&gt;                        } else {&lt;BR /&gt;                                push(@lines,$saves[$i]);&lt;BR /&gt;                        }&lt;BR /&gt;                }&lt;BR /&gt;&lt;BR /&gt;        push(@lines,$_);&lt;BR /&gt;&lt;BR /&gt;        if ($#lines &amp;gt; 0){&lt;BR /&gt;                foreach $i (0..$#lines)&lt;BR /&gt;                {&lt;BR /&gt;                        print $lines[$i];&lt;BR /&gt;                }&lt;BR /&gt;        }&lt;BR /&gt;                @lines = ();&lt;BR /&gt;                @saves = ();&lt;BR /&gt;        } else {&lt;BR /&gt;                unshift(@saves,$_);&lt;BR /&gt;&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;# perl testing.pl "c v f 3 4 5 6" filename&lt;BR /&gt;2006-1-3&lt;BR /&gt;a b c d e f g&lt;BR /&gt;e 1 2 g 4 5 6&lt;BR /&gt;d 1 2 3 4 5 6&lt;BR /&gt;c v f 3 4 5 6&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 20 Dec 2006 08:44:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019837#M745673</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2006-12-20T08:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: searching script help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019838#M745674</link>
      <description>GNU grep</description>
      <pubDate>Thu, 14 Jun 2007 03:52:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/searching-script-help/m-p/5019838#M745674</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2007-06-14T03:52:08Z</dc:date>
    </item>
  </channel>
</rss>

