Syntax Problem with awk

Hello,

I have perl script,which take some part of data in the file.
the below command works fine in normal cmd prompt.

`awk '/CDI/ && /[A-Z][0-9]/ && !/Result for/ {print $3 $5 > "final.txt"}' datalist.txt`;

`nawk -F"[)(]" '{print $2}' finalcdi.txt`;

But not working.

Afaik Perl does not know about backticks. If you want to execute system commands, system() function might be a better choice:
system - perldoc.perl.org
Perl is able to parse text with regular expressions too.

Perl knows about backticks but it interprets them as strings in double quotes and make interpolation of variables. So $1, etc. are perl variables, not awks. But you can use:

qx' cmd '

to prevent this.

I have given like below but it gives syntax error near "/ && ".Execution aborted.

qx 'awk '/CDI/ && /[A-Z][0-9]/ && !/Result for/ {print $3 $5 > "final.txt"}' datalist.txt'

---------- Post updated at 05:32 PM ---------- Previous update was at 04:48 PM ----------

hi,

even i tried using system command as below.it is executing the command but error comes.

code:
system ("awk '/CDI/ \&& /[A-Z][0-9]/ \&& \!/Result for/ {print \$3 \$5 > "final.txt"}' datalist.txt");
code/

It gives error

awk:syntax error near line1
awk:illegal statement near line1

This is because you have double quotes in your awk script, around the filename, final.txt:

I don't believe you need this. If you do, you can escape it by using the backslash (\), before each of them. The result should look like - \"final.txt\".

  • GP

This worked for me , inside perl

 
@v = `awk '/CDI/ && /[A-Z][0-9]/ && !/Result for/ {print \$1 \$2 > "final.txt"}' input_file`;

My system is :

  
uname -a
HP-UX avalon B.11.11 U 9000/800 3547052374 unlimited-user license