[英]Find/Replace using grep and Textwrangler
I'm using grep
on TextWrangler to find strings of this type: 我在TextWrangler上使用grep
来查找这种类型的字符串:
4,600.00
My regex command is the following: 我的正则表达式命令如下:
\d.\d{3}.\d{2}
which seems to find the strings correctly. 这似乎找到正确的字符串。 I would like to replace the string 4,600.00
with 4600.00
as I wish to save the data in a .csv
file. 我想用4600.00
替换字符串4,600.00
,因为我希望将数据保存在.csv
文件中。 How do I remove the comma from each number that I find? 如何从我找到的每个号码中删除逗号?
Search: (\\d{1,3}),(\\d{1,3})\\.(\\d{1,2})
搜索: (\\d{1,3}),(\\d{1,3})\\.(\\d{1,2})
Replace: \\1\\2.\\3
替换: \\1\\2.\\3
Works in TextWrangler. 适用于TextWrangler。
awk oneliner: awk oneliner:
awk --re-interval '{x=gensub(/([0-9]{1,3}),([0-9]{3}\.[0-9]{2})/,"\\1\\2","g");print x}' file
test: 测试:
kent$ awk --version|head -1
GNU Awk 3.1.6
kent$ echo "foo,bar,blah,46,000.00,some,more"|awk --re-interval '{x=gensub(/([0-9]{1,3}),([0-9]{3}\.[0-9]{2})/,"\\1\\2","g");print x}'
foo,bar,blah,46000.00,some,more
One way using sed
: 使用sed
一种方法:
sed -r 's/([0-9]{1,3}),([0-9]{3}\.[0-9]{2})/\1\2/g' file.txt
You could add the -i
flag to write the changes directly to the file. 您可以添加-i
标志以将更改直接写入文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.