How to remove the word if one of the characters in the word contains "m" or "M"?
I tried this, but it doesn't work:
echo 6.5G 66.5m | sed -e 's/[m][M]//g'
Your sed command is
This will remove only the string
mM from its input, because you've asked to match
m, followed by
You probably meant to write
[Mm] instead. You can get the same effect by adding the
/i option to the
s command, though:
Now this will remove all upper- or lower-case
$ echo 6.5G 66.5m | sed -e s/m//ig 6.5G 66.5
Your question asks how to remove entire words containing this letter. For that, we need to match any non-space characters before or after.
[^ ] matches a non-space character, and
[^ ]* matches zero or more non-space characters, so we want
s/[^ ]*m[^ ]*//ig
$ echo 6.5G 66.5m | sed -e 's/[^ ]*m[^ ]*//ig' 6.5G
$ echo Five Merry Women went fishing | sed -e 's/[^ ]*m[^ ]*//ig' Five went fishing
$ echo 6.5G 66.5m | sed -e 's/[[:space:]].*[mM]//g' 6.5G
Note that the "m" and "M" form one pattern - your (non-working) version looks for an "m" followed by an "M".
If you want to remove you can try this
[root@connect ~]# echo 6.5M 66.5m | sed -e 's/m//g' | sed -e 's/M//g' 6.5 66.5
Try This it will Delete The line containg 'm' or 'M'
echo 6.5G 66.5m | sed "/[mM]/d"