Replace two or more spaces in the text file with;

File1:

hello      world
foo   bar
a  word with a space

      

I need to replace all white spaces that are two or more long with a semicolon (;).

Result:

File2:

hello;world
foo;bar
a;word with a space

      

+2


source to share


3 answers


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

      



+7


source


$ 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

      



0


source


Try:

sed -e 's/  */;/g' file

      

-2


source







All Articles