Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignorecase in AWK

Tags:

awk

The following command is working as expected.

# some command | awk '/(\<^create\>|\<^alter\>|\<^drop\>)/,/;/'  create table todel1 (id int) max_rows=2 /*!*/; alter table todel1 engine=InnoDB /*!*/; create database common /*!*/; create database rules /*!*/; 

But it matches only the lower case "create", "alter" etc. I want to use IGNORECASE switch in the awk statement so that it will return all instances of the search term.

like image 833
shantanuo Avatar asked Mar 08 '11 05:03

shantanuo


People also ask

How do you make a case insensitive in Unix?

The key to that case-insensitive search is the use of the -iname option, which is only one character different from the -name option. The -iname option is what makes the search case-insensitive.

How awk works Linux?

The awk command's main purpose is to make information retrieval and text manipulation easy to perform in Linux. The command works by scanning a set of input lines in order and searches for lines matching the patterns specified by the user.


Video Answer


1 Answers

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 
like image 61
Andrew Yochum Avatar answered Sep 18 '22 21:09

Andrew Yochum