This is a bit late, but two answers to this question (including the accepted answer) mention doing awk 'IGNORECASE=1;...'
- i.e. putting IGNORECASE=1
as a condition, instead of a statement in a block.
This should not be done. It does set the variable as intended, but it also (as unintended) evaluates it as a boolean expression, returning true.
A true condition without a block will cause the line to always be printed. If it happens to match the following pattern, it will also be printed a second time.
What the accepted answer probably meant was awk '{IGNORECASE=1} ...'
, which sets the IGNORECASE
variable on each line of text. This can be further improved by using the BEGIN
condition to assign it only once. But a cleaner solution is to use the -v
flag to set the parameter outside of the script logic:
awk -v IGNORECASE=1 '/(\<^create\>|\<^alter\>|\<^drop\>)/, /;/'
Note that IGNORECASE
is specific to gawk. For a non gawk-specific method, the GNU Awk User's Guide suggests using tolower
in a pattern match:
awk '(tolower($0) ~ /(\<^create\>|\<^alter\>|\<^drop\>)/), /;/'
IGNORECASE = 1
as a condition (with side effect), rather than as a statement in a block. This condition is truthy, and will result in every line being printed at least once. – mwfearnley