简体   繁体   English

Mawk - 删除特殊字符

[英]Mawk - removing special characters

I use mawk.我用mawk。

I have a file:我有一个文件:

{1: [u'Bank Pocztowy'], 2: [u'Pekao']}

I want to get the result:我想得到结果:

{1: [uBank Pocztowy], 2: [uPekao]}

I tried this:我试过这个:

mawk '{gsub("\'",""); print}' file

Thank you for your help.谢谢您的帮助。

EDIT: Example:编辑:示例:

$ mawk '{gsub("\'",""); print}' file
> 

Your gsub should be as below:您的 gsub 应如下所示:

gsub(/\047/,"" )

chekc with

mawk '{gsub(/\047/,""); print}' file

I dont have mawk installed here.我这里没有安装mawk。 i only have nawk:我只有nawk:

tested with nawk:用 nawk 测试:

> echo "{1: [u'Bank Pocztowy'], 2: [u'Pekao']}" | nawk '{gsub(/\047/,"" ) ; print}'
{1: [uBank Pocztowy], 2: [uPekao]}

Alternatively ,If you want the solution in perl :或者,如果您想要 perl 中的解决方案:

> echo "{1: [u'Bank Pocztowy'], 2: [u'Pekao']}" | perl -pe "s/\'//g"
{1: [uBank Pocztowy], 2: [uPekao]}

you can cut out the final print too, and make it go faster你也可以剪下最后的印刷品,让它走得更快

 mawk/mawk2/gawk 'BEGIN { FS = "^$" } gsub(/[\047]+/, "") || 1'

Setting FS so not to spend time splitting fields.设置 FS 以免花时间拆分字段。 If single quotes exist, the gsub( ) return will handle the print automatically.如果存在单引号,gsub() 返回将自动处理打印。 The "or 1" is for the case when no single quotes exists that line. “或 1”适用于该行不存在单引号的情况。

Another method is use FS to detect the single quotes另一种方法是使用FS来检测单引号

 mawk/mawk2/gawk 'BEGIN { FS = "\047" } (NF == 1) || gsub(/[\047]+/, "")'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM