What operating system are you running this perl script on? What shell is being used by that operating system? When I run your command on using backtics on my system (Debian Linux, bash shell) I don't get an error at all.
If you need portability across operating systems, I recommend you stay away from backtics and pipes and instead use Perl functions. The following short script does the same thing as your grep/awk combination:
#strictures - put these two lines at the top of every Perl script
#these do a lot of the debugging work for you
use strict;
use warnings;
... lots of other stuff ...
# do: awk '/fileid/,/^-----/' logfile | grep specificdata
my $bPrint=0;
open LOGFILE, '<', "Monks/tmp/logfile.txt" or die;
while (my $line = <LOGFILE>) {
#equivalent to awk '/fileid/,/^-----/' logfile
$bPrint = 1 if $line =~ /fileid/;
$bPrint = 0 if $bPrint && $line =~ /^-----/;
#equivalent to grep specific data
print $line if $bPrint && $line =~ /specificData/;
}
close LOGFILE;
To learn more about the Perl concepts involved in the above code:
- strict and warnings explain what the two lines at the beginning mean and what they can do for you
- perlopentut - will explain how to open and close files in Perl
- retut - will explain how to use =~ to filter data using regular expressions. Perl regular expressions are much more powerful than the awk regular expressions with which you are probably familiar.
- perlport - things to watch out for if you are using Perl on multiple operating system to other.
Best, beth
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.