The I modifier to regular-expression matching is a GNU extension which
makes sed match regexp in a case-insensitive manner.
Test
$ 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
Convert each line to uppercase before testing whether it matches the pattern and if it does, print the string. 1 is the shortest true condition, so awk does the default thing: { print }.
if you want to save some typing, try awk. I don't think sed has that option
You can use the following:
Otherwise, you have the
/I
and n/i
flags:From man sed:
Test
GNU sed
Use the following, \b for word boundary
For versions of awk that don't understand the
IGNORECASE
special variable, you can use something like this:Convert each line to uppercase before testing whether it matches the pattern and if it does, print the string.
1
is the shortest true condition, so awk does the default thing:{ print }
.To use a variable, you could go with this:
This passes the shell variable
$foo
and transforms it to uppercase before the file is processed.Slightly shorter with bash would be to use
-v pattern="${foo^^}"
and skip theBEGIN
block.You can try