Loop usage with counter

view story

http://www.unix.com – Hi friends, I just want to try some thing with shell using loop and counter I have 30 Directory, in each directory number of files say 5, 10, 20 etc... Code: directory_1 directory_2 directory_n what I want to do is read files from directory_1 say 5 files if my counter is like this Code: m=2000  # M is for folder n=1          # N is for file counter for file in `ls *.dat |sort -t"_" -k2n,2`; do awk -F, 'FNR == 1{print '$m',$1,$2,$3,'$n',$5,$6,$7}' OFS="," $file >>file.csv n=$(( $n+1 )) done output wanted is something like (HowTos)