Artificial intelligent assistant

Parse file with Awk only when first row matches pattern I need to interrogate the header of a CSV file, and if a column exists proceed with the data rows. Context is when the data contains columns depending on when and what emitted it. Hoping for a "pure" Awk solution to keep business logic in a common language, but if this is not possible, interested in approaches that selectively deliver files with the header match to the Awk script. Using latest version of Gawk is always an option. **Edit to add pseudo code:** if column in header (NR==1): then proceed with rest of file, else stop processing file

to list files:

try


awk 'FNR == 1 && $4 == "whatever" { print FILENAME ;}' file1 ... filen |


which will select all file having whatever in fouth colum.

If you have funny name, just add quotes.


awk 'FNR == 1 && $4 == "whatever" { printf "\"s\"\
", FILENAME ;}' file1 ... filen |


to process one file


awk 'NR == 1 && $4 != "whatever" { exit ;} other patterns { other action;}' file


to process many file


awk 'NR == 1 && $4 != "whatever" { nextfile ;} other patterns { other action;}' file1 ... filen


which could be read as

* IF (condition not met) `NR == 1 && $4 != "whatever"`
* THEN skip this this file `{ nextfile ;}`
* ELSE proceed `other patterns { other action;}`

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy f4614133de36c5c26cfee877b5330bcc