File1中:

hello      world
foo   bar
a  word with a space

我需要用分号(;)替换长度为两个或更多的所有空格。

结果:

文件2:

hello;world
foo;bar
a;word with a space
有帮助吗?

解决方案

sed -e 's/  \+/;/g' File1 > File2

其他提示

$ gawk 'BEGIN{FS="  +"}{$1=$1}1' OFS=";" file
hello;world
foo;bar
a;word with a space

$ awk '{gsub(/  +/,";")}1' file
hello;world
foo;bar
a;word with a space

尝试:

sed -e 's/  */;/g' file
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top