在AWK中输出特殊字符-单引号


在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 "$\\`"}'  
$\`  
 

相关内容

    暂无相关文章