bash 如何删除文件中每一行的第一个逗号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2478232/
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-09-17 21:50:24  来源:igfitidea点击:

How to remove first comma on each line in a file

bashsedawk

提问by vehomzzz

Remove first comma on each line in a file. I presume sed is needed.

删除文件中每一行的第一个逗号。我认为 sed 是需要的。

回答by ghostdog74

sed

sed

sed -i.bak 's/,//' file

awk

awk

awk '{sub(",","")}1' file >temp; mv temp file

shell

贝壳

while read -r line
do
 echo "${line/,/}"
done <"file" > temp
mv temp file

回答by kzh

For first comma:

对于第一个逗号:

sed '/,//' < file

sed '/,//' < file

If first comma is first character:

如果第一个逗号是第一个字符:

sed '/^,//' < file

sed '/^,//' < file

回答by Beta

Yes, sed will do it.

是的,sed 可以做到。

sed s/,// < filename

回答by TMB

Yes,

是的,

first comma sed '/,//' < file

第一个逗号 sed '/,//' < 文件

first character that is a comma sed '/^,//' < file

第一个是逗号的字符 sed '/^,//' < 文件

USEFUL ONE-LINE SCRIPTS FOR SED

有用的 SED 单行脚本

回答by WisdomFusion

sed '/^,//' < file