Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

some strange behavior for awk when embedded in perl

Status
Not open for further replies.

keak

Programmer
Joined
Sep 12, 2005
Messages
247
Location
CA
Hi there,
I have a fairly simple awk line which I call from my command line:

Code:
cat ../directory1/out | grep ^diff |  awk '{print $5}' > ../directory1/differece

and this works fine when run from comamnd.



When I embed this exact same code in perl and run it from a web browser, the result "difference" file contains unformatted data (basically it prints the whole line instead of $5 into the text file) ..... am I missing something here?

Code:
`cat ../directory1/out | grep ^diff |  awk '{print $5}' > ../directory1/differece`
 
I'm not certain why awk isn't working for you, but I have a question: since you're already using a perl script, rather than using cat, grep and awk, why not rewrite it in perl?

This is untested, but should at least give you a start.
Code:
open INPUT, "< ../directory1/out" or die;
open OUTPUT, "> ../directory1/difference" or die;
while (<INPUT>) {
    if (/^diff/) {
        print OUTPUT (split)[5], "\n";
    }
}
close OUTPUT;
close INPUT;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top