Reputation: 23
In a Windows Server environment, having trouble with escaping quotes that are within quotes. Using the functioning batch code below as a base:
awk -F "|" "$4 ~ /JUVENILE/ {sum +=$6} END {printf sum}" sourcedata.file
Problems occur when trying to include "%.3f"
to printf. I am confused and unable to properly escape these quotes in my environment.
awk -F "|" "$4 ~ /JUVENILE/ {sum +=$6} END {printf """%.3f""", sum}" sourcedata.file
The above will work at the command prompt, but will not work in a simple batch file. I have also attempted to replace "%.3f"
with \"%.3f\"
and \""%.3f\""
and these also do not work in a batch file.
Upvotes: 2
Views: 607
Reputation: 204310
The standard advice for Windows to avoid their nightmarish quoting rules is:
a) Don't call the script from Windows. Install cygwin or similar to get a UNIX-like environment and then call the script from that, or...
b) Don't specify the script text on the command line in Windows, save it in a file instead, i.e. put this in a file named foo.awk
:
BEGIN { FS="|" }
$4 ~ /JUVENILE/ {sum +=$6}
END {printf "%.3f", sum}
and then execute it as awk -f foo.awk sourcedata.file
Upvotes: 1