How to remove extra spaces in variable HEAD?
HEAD="    how to  remove    extra        spaces                     "   Result:
how to remove extra spaces 
                Try this:
echo "$HEAD" | tr -s " "   or maybe you want to save it in a variable:
NEWHEAD=$(echo "$HEAD" | tr -s " ")   Update
To remove leading and trailing whitespaces, do this:
NEWHEAD=$(echo "$HEAD" | tr -s " ") NEWHEAD=${NEWHEAD%% } NEWHEAD=${NEWHEAD## } 
                        Using awk:
$ echo "$HEAD" | awk '$1=$1' how to remove extra spaces 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With