-2

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.

  • 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.unix.stackexchange.com/questions/145978/… – John Dec 27 '17 at 1:58
0

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....

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.