Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

soubalaji does not need double quote interpolation, as there are no perl variables that might need expansion embedded in his command string.

Instead he needs glob expansion. ./paz0*/home/fdm*/lo­gs/*CYUTI*21* presumably expands to a long list of matching files, which he wants to filter with gzgrep(*). Running a command via backticks ought to invoke a shell to do the expansion, however as I recall the shell invoked is sh which has few features compared with bash or the like.

If it where me, I would implement the whole thing in perl, that is use glob or File::Glob to expand the glob patten to a list of files, then open each through a zcat filter searching for matching lines.

Alternatively, soubalaji could use perl to expand the glob, feed that list into gzgrep, and then capture and filter the output. Something like:

my @file_list = glob './paz0*/home/fdm*/lo­gs/*CYUTI*21*'; my $command = 'gzgrep "00380-1037" ".join(' ',@file_list); open my $cmdFH, '-|', $command or die "Error running gzgrep $!"; my @matches = {grep qr/isTempDisabled Y/} <$cmdFH>; close $cmdFH; print @matches;

Note that the second use of grep is the internal perl function, and it is used to filter the list of matching lines that we get when the filehandle on the gzgrep command is called in an array context.

(*) could gzgrep be a typo? On my system the command to grep gzip compressed files is zgrep


In reply to Re^2: Use Unix command in Perl by chrestomanci
in thread Use Unix command in Perl by soubalaji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found