Search code examples
awkgzipgunzip

Feed unzipped files from all subdirectories into awk


I want awk to process all files in unzipped form from all sub-directories.

This is what I've tried: It works only for top level directory files.

for file in *
do
    awk -v f="$file" 'NF > 0 {print f; nextfile}' <(gunzip -cf $(find . -type f) "$file")
done

(My goal is not to just print non empty file names using awk, I just gave this as an example)


Solution

  • Assumptions:

    • we want awk to print the name of the zipped file
    • in the case of a zipped file that consists of a group of files we (still) only want to print the name of the zipped file, otherwise OP will need to provide more details on how to process the zipped file

    One idea:

    while read -r file
    do
        awk -v f="$file" 'NF>0 {print f; nextfile}' <(gunzip -cf "$file")
    done < <(find . -type f)