-3
IFS=$'\n'
for CITY in $(cat /home/user/CT.txt)
do
 FILES=/mnt/dir1/dir2/$CITY/*
 count=0
folder=''
 for f in $FILES
 do
  echo "Processing $f file..."
        ((count++))
        folder=$f
  # take action on each file. $f store current file name
   #cat $f
 done

Below is CT.txt content and directory structures :

cat CT.txt
Test1 Test2 Test3

cd Test1/
|_dir1
exm.xls
cd Test2
|_dir1
exm.xls

Output should:

i want only dir inside files should process under Test1 Test2 excluding .xls file

  • if the directory structure is wrong, please edit in your question – αғsнιη Aug 08 '17 at 12:50
  • While it's the same person with the same script, it seems (to me) to be an extension of the previous question, here asking how to exclude files from the loop, versus dealing with the spaces in the previous question. That doesn't excuse the lack of progress based on the referral to: "Why does my shell script choke on whitespace or other special characters?" – Jeff Schaller Aug 08 '17 at 13:14

1 Answers1

1

Without addressing the rest of your script, to skip files that end in ".xls":

[[ $f =~ .xls$ ]] && continue

Or, if you don't like that syntax:

case "$f" in
  (*.xls) continue;;
esac

Or, if you don't like that syntax:

shopt -s extglob
for f in /mnt/dir1/dir2/$CITY/!(*.xls)
do
  : etc
done
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • IFS=$'\n'

    for CITY in $(cat /home/user/CT.txt)

    do

    FILES=/mnt/dir1/dir2/$CITY/*

    count=0

    folder=''

    for f in $FILES

    do

    echo "Processing $f file..."

        ((count++))
    
        folder=$f
    
    

    i want to process only if there files folder. if there is any other file apart from that folder than exclude that.

    – Amrut Nadgiri Aug 08 '17 at 14:01