Reputation: 247
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
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
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