Saturday, 17 August 2013

Combine two regular expression rule in sed to remove unwanted characters from string

Combine two regular expression rule in sed to remove unwanted characters
from string

I am trying to remove all non alphanumerical characters and non space
characters and non dash non underscore characters
echo "$1" |sed 's/[^a-zA-Z0-9[:space:]]//g'
i want some thing like
echo "$1" |sed 's/[^\-\_a-zA-Z0-9[:space:]]//g'
How can i mix two regex rules together?
sample input is:
a-b
a_b
ab
a..
a.b
a b
a %b
a ^&n
I want this output:
a-b
a_b
ab
a
ab
a b
a b
a n

No comments:

Post a Comment