Artificial intelligent assistant

awk case insensitive with gsub I have `"|"` delimited text data, and want to transform a column values $ cat infile Mark|father Jason|SOn Jose|son Steffy|daugHter I want to search for (father|son|daughter) case insensitively and substitute any case of father to Father, any case of son to Son, any case of daughter to Daughter So outfile should look like this $ cat outfile Mark Father Jason Son Jose Son Steffy Daughter I'm trying different combination of IGNORECASE with sub or gsub, but it prints all entries as is in infile

I'd use a hash lookup instead of a regexp comparison and *sub() for efficiency and robustness (in case you decide to use a string that contains regexp metachars or backreferences or can be a substring of some other string):


$ cat tst.awk
BEGIN {
FS = "|"
split("Father|Son|Daughter",tmp)
for (i in tmp) {
map[tolower(tmp[i])] = tmp[i]
}
}
{ lc = tolower($2) }
lc in map {
$2 = map[lc]
}
{ print }



$ awk -f tst.awk file
Mark Father
Jason Son
Jose Son
Steffy Daughter

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a0f633b6d135b6b544548e60db0dc5d6