在AWK中輸出特殊字符-單引號
在AWK中輸出單引號實現方式比較特殊:
[html]
> uname
Linux
對於輸出字符串使用到單引號:
單引號-雙引號-單引號-轉義單引號-單引號-字符串-單引號-轉義單引號-單引號-雙引號-單引號(下劃線部分為輸出單引號,相同顏色符號對應)
[html]
> echo aaa | awk '{print "select * from A where name='\''TOM'\''"}'
select * from A where name='TOM'
對於輸出域變量使用到單引號:
單引號-雙引號-單引號-轉義單引號-單引號-雙引號-域變量-雙引號-單引號-轉義單引號-單引號-雙引號-單引號(下劃線部分為輸出單引號,相同顏色符號對應)
[html]
> echo TOM | awk '{print "select * from A where name='\''"$1"'\''"}'
select * from A where name='TOM'
對於輸出環境變量使用到單引號:
單引號-雙引號-單引號-轉義單引號-單引號-單引號-環境變量-單引號-單引號-轉義單引號-單引號-雙引號-單引號(下劃線部分為輸出單引號,相同顏色符號對應)
[html]
> key=TOM; echo aaa | awk '{print "select * from A where name='$key'"}'
select * from A where name=TOM
> key=TOM; echo aaa | awk '{print "select * from A where name='\'''$key''\''"}'
select * from A where name='TOM'
其它特殊字符:
$`(美元符、反引號)只需在雙引號內即可,\(反斜槓)需要在前面加上反斜槓
[html]
echo aaa | awk '{print "$\\`"}'
$\`