user1745860
user1745860

Reputation: 247

awk ignore case

file.txt

file format  = cust:hdb

file data =   ted Ref:4rm

read -p "Cust:" cust

User key in: ted ref

grep -i -q "$cust" "file"

System able to ignore case and read the input

read -p "NewCust:" cust2

User key in: Ted Ref

awk -F : -v OFS=: -v cust="$cust" -v cust="$cust2" -v hdb="$hdb" '$1==cust && $2==hdb {$1=cust2;}1' file

How do i set this so that the awk can ignore the case and update to file?

Upvotes: 0

Views: 647

Answers (2)

Guru
Guru

Reputation: 16994

One way:

IGNORECASE=1 awk -F : -v OFS=: -v cust="$cust" -v cust="$cust2" -v hdb="$hdb" '$1==cust && $2==hdb {$1=cust2;}1' file

Upvotes: 0

jordanm
jordanm

Reputation: 34964

In addition to IGNORECASE, you can convert the item you are matching to lowercase in GNU awk with tolower().

awk -F : -v OFS=: -v cust="$cust" -v cust="$cust2" -v hdb="$hdb" 'tolower($1)==cust && tolower($2)==hdb {$1=cust2;}1'

The GNU awk documentation offers this page on case sensitivity.

Upvotes: 4

Related Questions