<?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 Problem regarding use of grep in perl script in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408509#M42164</link>
    <description>Hi everybody!&lt;BR /&gt;I'm facing a problem in a perl script wherein I want to grep those lines from a file which start with "["(open square bracket).I have used two ways:-&lt;BR /&gt;-@list=`grep '^\[' filename`;&lt;BR /&gt;-system "grep '^\[' filename";&lt;BR /&gt;In both cases I'm getting the error message:&lt;BR /&gt;grep: [] imbalance&lt;BR /&gt;What is wrong with them and how to remove the problem??</description>
    <pubDate>Mon, 27 Apr 2009 08:51:00 GMT</pubDate>
    <dc:creator>Ajay Saini</dc:creator>
    <dc:date>2009-04-27T08:51:00Z</dc:date>
    <item>
      <title>Problem regarding use of grep in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408509#M42164</link>
      <description>Hi everybody!&lt;BR /&gt;I'm facing a problem in a perl script wherein I want to grep those lines from a file which start with "["(open square bracket).I have used two ways:-&lt;BR /&gt;-@list=`grep '^\[' filename`;&lt;BR /&gt;-system "grep '^\[' filename";&lt;BR /&gt;In both cases I'm getting the error message:&lt;BR /&gt;grep: [] imbalance&lt;BR /&gt;What is wrong with them and how to remove the problem??</description>
      <pubDate>Mon, 27 Apr 2009 08:51:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408509#M42164</guid>
      <dc:creator>Ajay Saini</dc:creator>
      <dc:date>2009-04-27T08:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem regarding use of grep in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408510#M42165</link>
      <description>It probably very much depends how Your system (I assume VMS, since we are in a VMS forum) defines the command grep.&lt;BR /&gt;In my system, grep is GNU grep from the GNV suite, and it works under the bash shell:&lt;BR /&gt;tmp.txt contains "[ at first position":&lt;BR /&gt;&lt;BR /&gt;bash&lt;BR /&gt;bash$ grep '^\[' tmp.txt &lt;BR /&gt;[ at first position&lt;BR /&gt;bash$ exit&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;If grep is invoked from DCL:&lt;BR /&gt;&lt;BR /&gt;grep '^\[' tmp.txt&lt;BR /&gt;grep.exe: Unmatched [ or [^&lt;BR /&gt;&lt;BR /&gt;which probably is the same as "[] imbalance".&lt;BR /&gt;&lt;BR /&gt;grep ^\[ tmp.txt  !Note without quotes!&lt;BR /&gt;[ at first position&lt;BR /&gt;&lt;BR /&gt;I.e. works without quotes!&lt;BR /&gt;&lt;BR /&gt;grep --version&lt;BR /&gt;grep (GNU grep) 2.4.2 Rev 1.4 (9-Jul-2001)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now I'm no perl expert, but for it looks strange to call external grep out of perl: perl's stength is string handling. Hein will surely present a one-liner doing the right thing :-)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Apr 2009 10:39:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408510#M42165</guid>
      <dc:creator>Joseph Huber_1</dc:creator>
      <dc:date>2009-04-27T10:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problem regarding use of grep in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408511#M42166</link>
      <description>What's wrong?  Well, the use of grep here (at all) seems rather wrong.  Perl has very capable regular expression processing.&lt;BR /&gt;&lt;BR /&gt;The lack of a problem statement (and the lack of platform and version information) is also somewhat of a problem.  With that, we'd know if this is perl on OpenVMS, or some other OS platform.  &lt;BR /&gt;&lt;BR /&gt;Using regex to parse an OpenVMS filename seems wrong, too; the OpenVMS filename syntax is entirely and thoroughly arcane, and does not lend itself to a regex.  (You know that &amp;lt; and &amp;gt; are legal syntax here, for instance?  Yes; the folks that wrote the PCSI tool didn't know that, either.)&lt;BR /&gt;&lt;BR /&gt;I'd start with one of the perl libraries for Perl and for Perl on VMS here, and see if there were parsing tools there.  Here are a couple:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://perldoc.perl.org/File/Basename.html" target="_blank"&gt;http://perldoc.perl.org/File/Basename.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://search.cpan.org/dist/perl/vms/ext/Filespec.pm" target="_blank"&gt;http://search.cpan.org/dist/perl/vms/ext/Filespec.pm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And I'd probably hook Perl to the RMS parsing routines long before I tried regex, either.  RMS knows the rules.  Having done (and regretted doing) parsing in code, it's best to punt this down to OpenVMS to handle.&lt;BR /&gt;&lt;BR /&gt;Here's one of many sites that discusses escaping reserved characters:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://tools.devshed.com/c/a/Web-Development/Beginning-Perl-Part-2-Escaping-Special-Characters/" target="_blank"&gt;http://tools.devshed.com/c/a/Web-Development/Beginning-Perl-Part-2-Escaping-Special-Characters/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=692014" target="_blank"&gt;http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=692014&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Why are you writing a filename parser?  Chances are, that's already been written and debugged by somebody.   (Is this homework?  If so, you have an interesting instructor for your class; this particular choice is a very good choice for an assignment for learning how to escape reserved characters.  And if the assignment was specifically to use grep here via a Unix bash or via GNV, that was a particularly devious choice for the assignment , as you have to deal both with perl and its processing and with grep and its processing; you'll very likely need to double up the escapement here.)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Apr 2009 12:50:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408511#M42166</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2009-04-27T12:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem regarding use of grep in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408512#M42167</link>
      <description>Hmm.  Seems improbable that I'm getting here before Hein for once.  But yes, this is a trivial problem with a Perl one-liner:&lt;BR /&gt;&lt;BR /&gt;$ type foo.txt&lt;BR /&gt;line&lt;BR /&gt;[line starting with bracket&lt;BR /&gt;another line&lt;BR /&gt;$ perl -nle "print if /^\[/;" &amp;lt; foo.txt&lt;BR /&gt;[line starting with bracket&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And as Joseph demonstrated, it's pretty darn simple with just grep.  The OP may well be having trouble with shell quoting rather than either Perl or grep, but without knowing what shell is in use that's hard to say.</description>
      <pubDate>Mon, 27 Apr 2009 18:03:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408512#M42167</guid>
      <dc:creator>Craig A Berry</dc:creator>
      <dc:date>2009-04-27T18:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem regarding use of grep in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408513#M42168</link>
      <description>Craig&amp;gt;&amp;gt; Seems improbable that I'm getting here before Hein for once&lt;BR /&gt;&lt;BR /&gt;Been busy... :-)&lt;BR /&gt;&lt;BR /&gt;It also seems silly to me to ask the shell to  activate 'grep' when perl has a perfectly find grep function build in !&lt;BR /&gt;&lt;BR /&gt;Just some silly examples:&lt;BR /&gt;&lt;BR /&gt;$ perl -e "@files=&amp;lt;*.*&amp;gt;; for (@files) { print qq($_\n)}"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl -e "open F,'&lt;LOGIN.COM&gt;; @nocomment = grep /^\$\s+[^!]/,@login; print for (@nocomment)"&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/LOGIN.COM&gt;</description>
      <pubDate>Tue, 28 Apr 2009 03:06:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problem-regarding-use-of-grep-in-perl-script/m-p/4408513#M42168</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-04-28T03:06:09Z</dc:date>
    </item>
  </channel>
</rss>

