ignorecase in AWK

For those who have an old awk where the IGNORECASE flag is useless:

Option 1

echo "CreAte" | awk '/^[Cc][Rr][Ee][Aa][Tt][Ee]/'

Option 2 (thanks @mwfearnley)

echo "CreAte" | awk 'tolower($0) ~ /^create/'

The following line executes an OR test instead of an AND :

echo -e "Create\nAny text" | awk 'IGNORECASE = 1;/^create/;'
Create
Create
Any text

The BEGIN special word solved the problem :

echo -e "Create\nAny text" | awk 'BEGIN{IGNORECASE = 1}/^create/;'
Create

Hope this helps.

Sebastien.


Add IGNORECASE = 1; to the beginning of your awk command like so:

bash-3.2$ echo "Create" | awk '/^create/;'
bash-3.2$ echo "Create" | awk 'IGNORECASE = 1;/^create/;'
Create

Tags:

Awk