Donbeo Donbeo - 1 month ago 4
Bash Question

shell how to apply a function to all the files in the directory and copy in another folder the results?

zcat 7days/src_file1.gz | head | ./addsubnets.py rndc_subnets.cfg |
gzip -9c > 7days_subnet/src_file1.gz


I have this shell function. It applies an operation to the file in the
7days
folder and saves it in the
7days_subnet
folder. How can I repeat this operations for all the files in
7days
?

Answer
for file in 7days/*; do
    file=${file#7days/}

    zcat 7days/"$file" | head | ./addsubnets.py rndc_subnets.cfg |
        gzip -9c > 7days_subnet/"$file"
done
Comments