I am trying to to find all the files with a given extension and awk the results and append into all.txt.

set -xe


find -iname \*.${EXT} -print0 | xargs -0 ls -l --time-style="+%b %Y" | awk '{print $NF,$3,$5,$6,$7}' OFS="\t" > ${EXT}.txt
awk -vextension="${EXT}" -vfiletype="${TYPE}" -vcompress="${COMP}" -vOFS="\t" '{print $0, extension, filetype, compress}' < ${EXT}.txt >> all.txt

I am able to get the output from find command,

.fielename.gz   Jason   197025960   May 2018

However, I am getting this syntax error from awk command,

+ awk -vextension=gzip -vfiletype=gz -vcompress=compressed '-vOFS=\t' '{print $0, extension, filetype, compress}'
awk: {print $0, extension, filetype, compress}
awk:                     ^ syntax error
  • Unable to replicate, I get no syntax error when attempting to run that awk invocation.
    – DopeGhoti
    Sep 20, 2018 at 16:40

1 Answer 1


Try replacing the extension variable name with something else, eg ext; in gawk, extension is a keyword / built-in.

$ gawk 'BEGIN{print extension}'
gawk: cmd. line:1: BEGIN{print extension}
gawk: cmd. line:1:                      ^ syntax error
$ gawk 'BEGIN{print ext}'  # OK
$ gawk -vextension=gzip 'BEGIN{print extension}'
gawk: fatal: cannot use gawk builtin `extension' as variable name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.