[*] 111, 22, 33, 44
sed 's/^\[\*\][[:space:]]*//' file were able to display the output as
111, 22, 33, 44 which means space still there.
So what is the correct
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The short answer is that this should do what you want:
Test it out like so:
echo '[*] 111, 22, 33, 44' | sed 's/[*]\|[[:space:]]//g'
A longer explanation follows.
The key ingredient that your expression was missing was the use of the
g command to perform global substitution. Without this command only the first match on each line will be replaced.
The most counter-intuitive bit (in my opinion) of my solution is how to include the square brackets inside a character class. For that, we refer to the sed manual:
‘]’ ends the bracket expression if it’s not the first list item. So, if you want to make the ‘]’ character a list item, you must put it first.
For further discussion on that topic, see the following post on SeverFault:
Alternatively, you could have taken your expression and piped it into another
sed command, e.g.:
echo '[*] 111, 22, 33, 44' \ | sed 's/^\[\*\]//' \ | sed 's/[[:space:]]//g'