sed -i '/first/i This line to be added'
In this case,how to ignore case while searching for pattern =first
Ignore case while replacing sed by default is case sensitive. To ignore the case -i flag can be used with sed command.
GNU sed and other version does support a case-insensitive search using I flag after /regex/.
You can make the awk to do case insensitive and match even for the words like “Iphone” or “IPHONE” etc. The IGNORECASE is a built in variable which can be used in awk command to make it either case sensitive or case insensitive. If the IGNORECASE value is 0, then the awk does a case sensitive match.
The key to that case-insensitive search is the use of the -iname option, which is only one character different from the -name option. The -iname option is what makes the search case-insensitive.
You can use the following:
sed 's/[Ff][Ii][Rr][Ss][Tt]/last/g' file
Otherwise, you have the /I
and n/i
flags:
sed 's/first/last/Ig' file
From man sed:
I
i
The I modifier to regular-expression matching is a GNU extension which makes sed match regexp in a case-insensitive manner.
$ cat file
first
FiRst
FIRST
fir3st
$ sed 's/[Ff][Ii][Rr][Ss][Tt]/last/g' file
last
last
last
fir3st
$ sed 's/first/last/Ig' file
last
last
last
fir3st
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With