sed regexp address case-insensitive matching

How to specify a sed regexp address which is case-insensitive?

E.g.,

sed '/my-kw/d'

But I want sed to remove lines with my-kw in any cases.

Thanks

1

3 Answers

sed '/my-kw/Id'

This will perform the match case-insensitive.

The switch is in uppercase itself, to avoid confusion with the i command that is offered by sed to insert a line into the stream.

4

Just use the I switch:

$ echo fooFOO | sed 's/o/a/Id'
faaFaa

From the sed FAQ:

GNU sed 3.02 and ssed also offer the /I switch for doing a case-insensitive match. For example,

echo ONE TWO | sed "s/one/unos/I" # prints "unos TWO"
4

This might work for you:

sed '/[mM][yY]-[kK][wW]/d' file or:

sed 'h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;/MY-KW/d;x' file

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like