更换`'`字符用awk [英] replacing the `'` char using awk

查看:148
本文介绍了更换`'`字符用awk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个行: 在其中,我想摆脱的。我想用 AWK 这一点。我试着用:

I have lines with a single : and a' in them that I want to get rid of. I want to use awk for this. I've tried using:

 awk '{gsub ( "[:\\']","" ) ; print $0 }'

 awk '{gsub ( "[:\']","" ) ; print $0 }'

 awk '{gsub ( "[:']","" ) ; print $0 }'

他们不工作,但返回错误无可匹敌的。。当我把

 awk '{gsub ( "[:_]","" ) ; print $0 }'

然后它的工作原理,并删除所有 _ 字符。我怎样才能摆脱 字符?

then It works and removes all : and _ chars. How can I get rid of the ' char?

推荐答案

您可以使用:


  1. 八code的单引号:

  1. Octal code for the single quote:

[:\47]


  • 双引号内的单引号,但在这种情况下,特别
    字符将被外壳扩展:

  • The single quote inside double quotes, but in that case special characters will be expanded by the shell:

    % print a\': | awk "sub(/[:']/, x)"        
    a
    


  • 使用一个动态的正则表达式,但也有相关的性能问题
    这种方法:

  • Use a dynamic regexp, but there are performance implications related to this approach:

    % print a\': | awk -vrx="[:\\\']" 'sub(rx, x)'  
    a
    


  • 这篇关于更换`'`字符用awk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆