A snippet of a typical tsv file I have used
10 Interstellar Main Theme Extended UDVtMYqUAyw
11 Journey XvG78AmBLc4
12 Jurassic Park Music & Ambience Amazing Soundscapes and Music PPl__iyIg6w
13 Lord of the Rings Sound of The Shire chLZQtCold8
14 Lord of the Rings The Shire: Sunset at Bag End uBmbI8dzc-M
The following searches for lord (case insensitively) in 2nd column of all tsv files:
awk '$2~IGNORECASE = 1;/lord/{print}' *.tsv
13 Lord of the Rings Sound of The Shire chLZQtCold8
14 Lord of the Rings The Shire: Sunset at Bag End uBmbI8dzc-M
Now, I wanted to pass Lord
as a bash environment variable:
$ awk -v Pattern="Lord" '$2~Pattern{print}' *.tsv
13 Lord of the Rings Sound of The Shire chLZQtCold8
14 Lord of the Rings The Shire: Sunset at Bag End uBmbI8dzc-M
Problem
How to do the match of pattern case insensitively?
I tried the following but it doesn't work
awk -v Pattern="lord" '$2~IGNORECASE = 1;Pattern{print}' *.tsv
awk -v Pattern="lord" 'IGNORECASE = 1;$2~Pattern{print}' *.tsv
awk -v Pattern="lord" 'BEGIN {IGNORECASE = 1} {$2~Pattern{print}}' *.tsv
awk -v Pattern="Lord" '{IGNORECASE = 1; $2~Pattern}' *.tsv
awk -v Pattern="Lord" '{IGNORECASE = 1; $2~Pattern}'
does not work. awk -W version GNU Awk 5.0.1 – Porcupine Jun 15 '21 at 01:22awk -v Pattern="Lord" '{IGNORECASE = 1;} $2~Pattern' *.tsv
which also works but unnecessarily re-assignsIGNORECASE = 1
for every record – steeldriver Jun 15 '21 at 01:30