[英]vim/sed remove white spaces column wise
i have a CSV file with 3 columns.我有一个包含 3 列的 CSV 文件。 It looks like this看起来像这样
col1,col2,col3
123,abc , 2015-01-01
246,def , 2015-02-02
How can i remove the white space in col3 only using vim/sed?如何仅使用 vim/sed 删除 col3 中的空白?
expected output:预期输出:
col1,col2,col3
123,abc ,2015-01-01
246,def ,2015-02-02
In vim, this command works for your example:在 vim 中,此命令适用于您的示例:
%s/,[^,]*$/\=substitute(submatch(0)," ","","g")
$ cat foobar.csv
col1,col2,col3
123,abc , 2015-01-01
246,def , 2015-02-02
$ sed 's/\(.*\),\(.*\),\(\s*\)\(.*\)/\1,\2,\4/' foobar.csv
col1,col2,col3
123,abc ,2015-01-01
246,def ,2015-02-02
Remember the -i
flag if you want to edit the file in place.如果要就地编辑文件,请记住-i
标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.