The below command works fine when I run it manually but when I call it from perl script using backticks or system command, it gives this error
sh: -c: line 0: syntax error near unexpected token `('
Script snapshot:
#Find contents of myFile in zipfile and output the matched records to output.txt
$cmd = "awk -F\"|\" 'NR==FNR{hash[\$0]=1;next} \$237 in hash' $myFILE <(unzip -p $zipfile *XYZ*) >> output.txt";
$result=`$cmd`;
It seems that we cannot call a subshell i.e. (unzip ...) within a system call through perl. Please advise as I have been struggling since a couple of days.
awk? This way you shell out (with backticks), then run a command (awk, for which you need to escape things), run another program in a subshell of that shell (unzip, for which you need to escape things), with redirections ... why not just do all processing (of unzip's return) in Perl, if the script is in Perl? - zdim<( ... )is not validshsyntax - ikegamiunzipout of your (Perl) script and process its output in that (Perl) script. Use Perl's (superb) native text-processing capabilities, instead of shelling out to useawk. (I get the idea: you have a command-line withawkthat works and you'd like to "just use it" in the script; but that makes it really much harder, error-prone, and brittle. And awkward.) - zdim