File1中:
hello world
foo bar
a word with a space
我需要用分号(;)替换长度为两个或更多的所有空格。
结果:
文件2:
hello;world
foo;bar
a;word with a space
答案 0 :(得分:7)
sed -e 's/ \+/;/g' File1 > File2
答案 1 :(得分:0)
$ 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
答案 2 :(得分:-2)
尝试:
sed -e 's/ */;/g' file