<?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: Perl grep question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246992#M714722</link>
    <description>open (INFILE,"&lt;INFILE&gt;&lt;/INFILE&gt;while(&lt;INFILE&gt;) {&lt;BR /&gt;        chomp;&lt;BR /&gt;        if (/AccountName:\s+Unix/ ... /Description:/) {&lt;BR /&gt;                        print "$_\n";&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;forgive the spacing problem but the if statement should be on the same line.&lt;BR /&gt;Hopefully this is what you are looking for&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Scott Palmer&lt;/INFILE&gt;</description>
    <pubDate>Wed, 14 Apr 2004 11:23:45 GMT</pubDate>
    <dc:creator>Scott Palmer_1</dc:creator>
    <dc:date>2004-04-14T11:23:45Z</dc:date>
    <item>
      <title>Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246981#M714711</link>
      <description>I need to pull blocks of information from a log if the block meets a condition.&lt;BR /&gt;&lt;BR /&gt;The log is set up as follows:&lt;BR /&gt;Account Name:&lt;BR /&gt;User Name:&lt;BR /&gt;Date:&lt;BR /&gt;Time:&lt;BR /&gt;Description:&lt;BR /&gt;&lt;BR /&gt;I want to be able to pull all blocks that have an account name like Unix.  Is there a way in perl to say find a line with Account Name = Unix and give me all other information until the next blank line?</description>
      <pubDate>Tue, 13 Apr 2004 14:06:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246981#M714711</guid>
      <dc:creator>Jason Berendsen</dc:creator>
      <dc:date>2004-04-13T14:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246982#M714712</link>
      <description>probably a better way, but I would do something like this. &lt;BR /&gt;&lt;BR /&gt;open F, "&amp;lt;$ARGV[0]" or die "$!";&lt;BR /&gt;while (&lt;F&gt;) {&lt;BR /&gt;    if (/^$/) {&lt;BR /&gt;        $go_on="";&lt;BR /&gt;        next;&lt;BR /&gt;    }&lt;BR /&gt;    if (/Account Name/) {&lt;BR /&gt;        ($label, $data)=split/:/;&lt;BR /&gt;        if ($data =~ /Unix/) {&lt;BR /&gt;            $go_on = 1;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;    print if $go_on;&lt;BR /&gt;}&lt;BR /&gt;close F;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/F&gt;</description>
      <pubDate>Tue, 13 Apr 2004 14:27:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246982#M714712</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2004-04-13T14:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246983#M714713</link>
      <description>perl -ne 'print if /^Account Name: Unix/../^$/'&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 13 Apr 2004 14:42:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246983#M714713</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-04-13T14:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246984#M714714</link>
      <description>nice one liner. Rodney</description>
      <pubDate>Tue, 13 Apr 2004 15:04:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246984#M714714</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2004-04-13T15:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246985#M714715</link>
      <description>Nice one liner indeed.&lt;BR /&gt;&lt;BR /&gt;Now if you need to do more than just the print, then yo may want to consider the more classical 'set flag when in range' approach:&lt;BR /&gt;&lt;BR /&gt;perl -ne '$block=1 if (/^Account Name: Unix/); print if ($block); $block=0 if (/^$/); ' &amp;lt; your-file&amp;gt;&lt;BR /&gt;&lt;BR /&gt;flip the print and block=0 sub commands depending on whether you want to retain the empty line or not.&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Apr 2004 16:06:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246985#M714715</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-04-13T16:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246986#M714716</link>
      <description>Thanks for each of the responses, I'm sure each way works fine.  But, due to my inexperience with Perl I am having trouble with the one liners.  Let me show you my test input file called /tmp/log.tmp:&lt;BR /&gt;&lt;BR /&gt;Account Name: schmoe&lt;BR /&gt;User Name: Joe Schmoe&lt;BR /&gt;Date: 04/14/2004&lt;BR /&gt;Time: 10:10&lt;BR /&gt;Description: Test&lt;BR /&gt;&lt;BR /&gt;Account Name: doej&lt;BR /&gt;User Name: John Doe&lt;BR /&gt;Date: 04/14/2004&lt;BR /&gt;Time: 10:10&lt;BR /&gt;Description: Test&lt;BR /&gt;&lt;BR /&gt;I try the following one liner and get a blank line for a return:&lt;BR /&gt;&lt;BR /&gt;perl -ne 'print if /^Account Name: Unix/./^$/' /tmp/log.tmp&lt;BR /&gt;&lt;BR /&gt;I then try the other one liner and get 00000 for a return:&lt;BR /&gt;&lt;BR /&gt;perl -ne '$block=1 if(/^Account Name: Unix/); print ($block); $block=0 if (/^$/);' /tmp/log.tmp&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am sure I am making a very dumb mistake but as of yet I can't find it.  Is my syntax wrong????&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Apr 2004 09:26:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246986#M714716</guid>
      <dc:creator>Jason Berendsen</dc:creator>
      <dc:date>2004-04-14T09:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246987#M714717</link>
      <description>Jason,&lt;BR /&gt;&lt;BR /&gt;How about a sed solution:&lt;BR /&gt;&lt;BR /&gt;# print paragraph if it contains AAA (blank lines separate paragraphs)&lt;BR /&gt; # HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below&lt;BR /&gt; sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;From "Handy One-Liners for Sed" (attached).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Wed, 14 Apr 2004 09:31:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246987#M714717</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2004-04-14T09:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246988#M714718</link>
      <description>Well, the obvious problem is that your Perl script is looking for "Account Name: Unix" but there is no such entry in your test file.&lt;BR /&gt;&lt;BR /&gt;Also because the Forum's HTML code (any HTML for that matter) doesn't handle whitespace well, make sure that the expected string exactly matches the input.</description>
      <pubDate>Wed, 14 Apr 2004 09:38:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246988#M714718</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-14T09:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246989#M714719</link>
      <description>All of the perl. Is looking for the word Unix. However now I see you want unix like usernames. &lt;BR /&gt;&lt;BR /&gt;That changes the expression that is needed in order for the patterns to match. &lt;BR /&gt;&lt;BR /&gt;An actual data sample, of one that should match and one that should not match, would help. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Apr 2004 09:39:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246989#M714719</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2004-04-14T09:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246990#M714720</link>
      <description>I obviously wasn't paying attention when I put Unix in.  I would like to use SED but I need this script to be portable to the Wintel environment with little modification.  In my earlier example file is there a way to pull the whole paragraph associated with the line User: Joe Schmoe?  I need all the information associated with this name.</description>
      <pubDate>Wed, 14 Apr 2004 10:51:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246990#M714720</guid>
      <dc:creator>Jason Berendsen</dc:creator>
      <dc:date>2004-04-14T10:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246991#M714721</link>
      <description>I was able to figure it out using Rodney's and Hein's one liner.  Thanks for all the help.</description>
      <pubDate>Wed, 14 Apr 2004 11:19:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246991#M714721</guid>
      <dc:creator>Jason Berendsen</dc:creator>
      <dc:date>2004-04-14T11:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Perl grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246992#M714722</link>
      <description>open (INFILE,"&lt;INFILE&gt;&lt;/INFILE&gt;while(&lt;INFILE&gt;) {&lt;BR /&gt;        chomp;&lt;BR /&gt;        if (/AccountName:\s+Unix/ ... /Description:/) {&lt;BR /&gt;                        print "$_\n";&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;forgive the spacing problem but the if statement should be on the same line.&lt;BR /&gt;Hopefully this is what you are looking for&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Scott Palmer&lt;/INFILE&gt;</description>
      <pubDate>Wed, 14 Apr 2004 11:23:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-grep-question/m-p/3246992#M714722</guid>
      <dc:creator>Scott Palmer_1</dc:creator>
      <dc:date>2004-04-14T11:23:45Z</dc:date>
    </item>
  </channel>
</rss>

