Замените два или более пробелов в текстовом файле на ;

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

  •  06-07-2019
  •  | 
  •  

Вопрос

Файл1:

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