I have a directory with a few dozens of files. I would like to do something with every second file from this directory. By now I only used find
command but with this I process all files:
find ./dir/ -type f -exec cat {} \;
for file in `find dir -type f | awk 'NR % 2 == 0'`; do
echo $file
done
NR
is the current row number. To get odd rows, use ... == 1
.
cnt=0;
for file in $(find ./dir -type f); <-- if not too many matches
do
let cnt=cnt+1;
if [ $cnt -eq 2 ];
then echo $file; <-- do something
cnt=0; <-- alternate file
fi;
done
or
second_file=$(find -type f | head -2 | tail -1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With