Say I have a variable "x" defined as ....
x = "abc 123 xyz 456"
Note: the # of spaces in each grouping is : 3 2 4 respectively and will always vary in # of spaces.
I want to replace each group of spaces with some value, say "P". Anotherwords, I want to treat each space grouping individually and replace with a single value irregardless of the number of spaces in each grouping.
For example, my intended result should be:
newx = "abcP123PxyzP456"
The following doesn't get what I want:
newx='echo "abc 123 xyz 456" | /usr/xpg4/bin/sed s/"([[:space:]]\)"/"P"/g'; echo $newx
Resulting newx: abcPPP123PPxyzPPPP456
Notes:
The reason I'm using the [[:space:]] class of characters is because the spaces could potentially be tabs (or multiple # of tabs).
I tried using the the folowing:
newx='echo "abc 123 xyz 456" | /usr/xpg4/bin/sed s/"([[:space:]]\)."/"P"/g'; echo $newx
Resulting newx: abcPP123PxyzPP456
Close, but not quite there ... any suggestions?
x = "abc 123 xyz 456"
Note: the # of spaces in each grouping is : 3 2 4 respectively and will always vary in # of spaces.
I want to replace each group of spaces with some value, say "P". Anotherwords, I want to treat each space grouping individually and replace with a single value irregardless of the number of spaces in each grouping.
For example, my intended result should be:
newx = "abcP123PxyzP456"
The following doesn't get what I want:
newx='echo "abc 123 xyz 456" | /usr/xpg4/bin/sed s/"([[:space:]]\)"/"P"/g'; echo $newx
Resulting newx: abcPPP123PPxyzPPPP456
Notes:
The reason I'm using the [[:space:]] class of characters is because the spaces could potentially be tabs (or multiple # of tabs).
I tried using the the folowing:
newx='echo "abc 123 xyz 456" | /usr/xpg4/bin/sed s/"([[:space:]]\)."/"P"/g'; echo $newx
Resulting newx: abcPP123PxyzPP456
Close, but not quite there ... any suggestions?