微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从特定字段中删除引号 – 引号之间的整数

我想从引号之间有整数的特定字段中删除引号。

从这一行: "AAA","99"

到这一行: "AAA",99

win7 express js:'express'在cmd中无法识别

Linux重命名命令大写的第一个字母

htaccess中的mod_rewrite:防止循环的最好方法

在PowerShell中,如何将环境variables(如$ SystemRoot $)转换为string的一部分?

Windowsbatch file中的正则expression式

在Windows系统中recursion重命名文件夹和文件

如果文件或目录存在,则RewriteCond跳过规则

奇怪的bug – std :: regex只匹配前两个string

我怎样才能轻松获得在C中的正则expression式select?

使用Python分割ps的输出

使用sed :

s='"AAA","99"' sed 's/"([0-9]*)"/1/g' <<< "$s" "AAA",99

试试这个GNU sed:

echo '"AAA","99"' | sed -E 's/"([0-9]+)"$/1/'

输出

“AAA”,99

用awk:

awk -F,'BEGIN { OFS = FS } $2 ~ /^"[0-9]+"$/ { gsub(/"/,"",$2) } 1'

这工作如下:

BEGIN { OFS = FS } # Delimit output the same way as the input $2 ~ /^"[0-9]+"$/ { # if the second field ($2) consists of only numbers encased # by double quotes (ie,matches the regex ^"[0-9]"$) gsub(/"/,$2) # remove the quotes from it } 1 # print in any case

为了使任何工作(而不仅仅是一个特定的领域),做一个循环替换:

awk -F,'BEGIN { OFS = FS } { for(i = 1; i <= NF; ++i) if($i ~ /^"[0-9]+"$/) { gsub(/"/,$i) } } 1'

这里改变的一点是

{ # Do this unconditionally in every line: for(i = 1; i <= NF; ++i) { # wade through all the fields if($i ~ /^"[0-9]+"$/) { # then do with them the same thing as before. gsub(/"/,$i) } } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐