-1

Using awk,
how we can remove extra spaces, where it finds more than one space?
We just need to keep one space between words, as usual.
The file size is 3kb.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Nayla
  • 1
  • 2
    tr -s " " 4 more to go... – jesse_b Dec 26 '17 at 23:39
  • 3
    Can you give a (minimal) example? Since the default output field separator is a single space, it's usually sufficient to ensure that at least one field in each record is re-evaluated e.g. awk '{$1=$1} 1' somefile – steeldriver Dec 26 '17 at 23:41
  • Fully explained here.https://unix.stackexchange.com/questions/145978/replace-multiple-spaces-with-one-using-tr-only – John Dec 27 '17 at 01:58

1 Answers1

1

Since you are not giving a kind of input sample / expected output i will make my guess:

With awk:

$ echo "$a"
one two     three                  four
$ echo "$a" |awk -v OFS=' ' '{$1=$1}1'
one two three four

With bash:

$ echo "$a"
one two     three                  four
$ echo $a #mind the absence of quotes around the variable
one two three four

Also tr -s ' ' will work fine....