问题
I use an embedded awk code in a shell script:
I have some variable assignments at the BEGIN part of it:
\
BEGIN { FS=","; OFS=","; service_not="false"; end_of_line="\n"; is_setup_gps="false"; \
\
a=6378137.0 ; \
b=6356752.3142 ; \
f=(a-b)/a ; \
e=sqrt(f*(2-f)) ; \
} \
\
So I need '\' at the end of each line (to have an entire awk script embedded in .sh).
BUT: for the lines: a=...; b=...; f=...; the '\' causing errors...: mawk: 57: unexpected character '\'
Why?
UPD: Embedding of awk in the bash script:
#!/bin/bash
... all shell commands ...
mawk '... ; \
... ; \
... ; \
' file_to_parse
回答1:
The quotes around the AWK script protect the newlines. No backslashes are necessary within them.
来源:https://stackoverflow.com/questions/12349873/awk-embedded-script-issue-unexpected-character