samedi 29 août 2020

If-then loop for sub-directories, if the lines in the file are more than 2

A directory contains 30 sub-directories (all end with _g). In each sub-directory, a file named report.txt exists. I need to loop for all sub-directories and execute statement one if the lines in the file report.txt are greater than 2, or statement two if less than 2.

I tried using this script, but I am not getting the exact output.

#!/bin/bash
File=report.txt
for g in *_g;
if ((awk 'END{print NR}' $g/"$File" > 2)); then
echo "$g:";
    Statement 1 "$g"/report.txt
echo "------------------";
else 
echo "$g:";
    Statement 2 "$g"/report.txt
echo "------------------";
fi
done

Aucun commentaire:

Enregistrer un commentaire