Linux 从 grep 输出中删除字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12668020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:28:29  来源:igfitidea点击:

Removing characters from grep output

linuxbashgrep

提问by Sam

I've been whittling down my grep output (which comes down to a listing of numbers that I intend to associate with other fields.) My problem is that numbers above 999 have commas in them, and I'm wondering how to print the output with out the commas.

我一直在缩减我的 grep 输出(归结为我打算与其他字段关联的数字列表。)我的问题是 999 以上的数字中有逗号,我想知道如何打印输出没有逗号。

so instead of the output being:

所以而不是输出是:

1,200,300

it would just be:

它只是:

1200300 

Any suggestions for an additional pipe command that I could add?

关于我可以添加的额外管道命令的任何建议?

Thanks

谢谢

采纳答案by Akhil Thayyil

Try this

尝试这个

< your command > | tr -d ','

tr will remove all commas

tr 将删除所有逗号

回答by John3136

 < your command > | sed -e 's/,//g'

This will replace all commas with "nothing" without changing anything else.

这将用“无”替换所有逗号而不更改任何其他内容。

回答by Vijay

instead of grep use a single awk command like below

而不是 grep 使用单个 awk 命令,如下所示

awk '/your pattern/{gsub(",","");print}' your_file