2

I am attempting to to only keep customers that contain certain words. Here is an example

< newname.txt awk 'BEGIN {FS=","} $7~/USA|United States/' > usa.txt

The problem I am having is if they had usa, UNITED STATES or UnItEd StAtEs then they would not export due to them being capitals. How can I run this command without writing the same word multiple times with capitals/lowercase.

3

You can try to cheat it with using tolower or toupper:

awk 'BEGIN {FS=","} tolower($7)~/usa|united states/'

or

awk 'BEGIN {FS=","} toupper($7)~/USA|UNITED STATES/'
1

You can use the IGNORECASE flag (!=0) to ignore the case on all regular expressions. At least that is gawk.

As requested: an example

echo "eXaMpLe"|awk '{IGNORECASE=1}
/example/ { print $0; }
'
eXaMpLe
  • 1
    You've got half an answer: please show a demonstration. – glenn jackman Jun 18 '15 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.