How to perform case insensitive search and replace in Linux

Sed command can be used to perform search and replace keywords in Linux. But its case sensitive by default.

We need to add options to make it case insensitive.

Let us see the example queries.

#sed -e 's/word1/word1/gI' file.txt

The above command will perform case insensitive search and replace. We need to replace word1, word2 and file.txt with the corresponding values.

If the system having an older version of sed, we need to use an alternative.

#sed 's/[wW][oO][rR][dD]1/word2/g' file.txt

We need to replace word1, word2 and file.txt with the corresponding values.

That's all…

Leave a Reply

Your email address will not be published. Required fields are marked *