0
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?

4

2 回答 2

4

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.

于 2013-01-22T04:51:56.597 回答
0

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
于 2013-01-22T04:47:57.600 回答