テキストファイル内の2つ以上のスペースを;に置き換えます。

StackOverflow https://stackoverflow.com/questions/1616638

  •  06-07-2019
  •  | 
  •  

質問

File1:

hello      world
foo   bar
a  word with a space

長さが2つ以上のすべての空白をセミコロン(;)に置き換える必要があります。

結果:

File2:

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