I am trying to run a command on multiple files that would print the row if the first column is equal to “aaa” or is equal to “bbb” and add a column before that with the name of the file.
Sample file (sample.tsv.gz):
aaa, 111, 222
bbb, 333, 444
ccc, 555, 666
I want the output to be:
sample.tsv.gz, aaa, 111, 222
sample.tsv.gz, bbb, 333, 444
My command is:
zcat *.tsv.gz | awk '{if ($1==“aaa”||$1==“bbb”) {print FILENAME (NF?",":"") $0}}'
The output I get is:
-, aaa, 111, 222
-, bbb, 333, 444
How do I fix this?