awk embedded script issue (unexpected character '\')

时光怂恿深爱的人放手 提交于 2020-01-15 13:06:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!