Removing spaces from string

I want a user to be able to paste in a string like "01 3F 20 1F" and have the script reformat it to "013F201F" to pass it on to the next step.

I was trying to figure it out with awk but wasnt working well.

Never mind, found answer. did not know about tr :slight_smile:

use sed..

$ echo "01 3F 20 1F" | sed 's/ //g'
013F201F

found the answer by yourself thats good.....

You can do something like this--

echo "01 3F 20 1F" | tr -d " "


# a="01 3F 20 1F"
# echo ${a// /}
013F201F

just another way :slight_smile:

echo "A B C E"|awk '/ /{gsub(" ","")}1'
# echo "A B C E"| awk '$1=$1' OFS=""
ABCE

this won't work for the below case :smiley:

 
fnsonlu1-/home/fnsonlu1> echo "A   VB        CV"| awk '$1=$1' OFS=""
A   VB        CV

# echo "A   VB        CV"| awk '$1=$1' OFS=""
AVBCV