استبدال اثنين أو أكثر من المساحات داخل ملف نصي مع.

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

  •  06-07-2019
  •  | 
  •  

سؤال

وFILE1:

hello      world
foo   bar
a  word with a space

ولست بحاجة لاستبدال كافة المسافات وهما أو أكثر في الطول مع منقوطة (؛).

والنتيجة:

و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