Cut command not working in for loop

grep -Fxvf testdata.xls file_GTDA1.xls >file_GTDA.xls

SLS_COUNT=`grep 'GTDA_Dly_Sls' file_GTDA.xls |wc -l`
PMIX_COUNT=`grep 'GTDA_Dly_Pmix' file_GTDA.xls |wc -l`

if [ $SLS_COUNT -gt 0 ]; then
                var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'`
                var4="|"
                for i in $var1
                do
                var3=`cut -d "$var4" -f18,19 $i|sort -u`
                var2=$var4""$var3
                sed -n 's/'"$var2"'//p' $i> ./temp/$i
#                sed -e 's/'"$var2"'//p' $i> ./temp/$i
                done
                echo " GTDA sales done"
fi

if [ $PMIX_COUNT -gt 0 ]; then
                var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Pmix_'`
                var4="|"
                for i in $var1
                do
                var3=`cut -d "$var4" -f12,13 "$i"|sort -u`
                var2=$var4""$var3
                sed -n 's/'"$var2"'//p' $i> ./temp/$i
                done
                echo " GTDA Pmix done"
fi

when i am running above code it is giving me below error:

cut: GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv: No such file or directory
sed: can't read GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv: No such file or directory
 GTDA sales done
cut: GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv: No such file or directory
cut: GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv: No such file or directory
cut: GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv: No such file or directory
cut: GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv: No such file or directory
 GTDA Pmix done

Thanks in advance!!!

Hi Renuk,

Where all these *.psv files located ? Are they in the same dir where your script is running ?

Thanks
Pravin

The error message is quite explicit : "No such file or directory"

Make sure that the file you are processing do exist and that you are in the right directory to process them.

cat file_GTDA.xls | grep 'GTDA_Dly_Sls_' | while read f
do ls -ld $f
done

@pravin: files are in file_GTDA.xls and in same path.

/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> more file_GTDA.xls
GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv
GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv

What output you have passing these commands ?

$ cd /dm/RMDW_LandingZone/dev/work_area/ABaC_reregister 
$ ls -ld GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv

I guess some files that are reported in your *.xls sheet are missing at operating system level

hi,

i tried this command it is giving below error:
ls -ld GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv
/bin/ls: cannot access GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv: No such file or directory

but my path contains .xls file which contains many files in it..

/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> more file_GTDA.xls
GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv
GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv

---------- Post updated at 02:45 PM ---------- Previous update was at 02:32 PM ----------

hi,

the problem is the files which i am passing to temp folder after below command ...

var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'`
                var4="|"
                for i in $var1
                do
                var3=`cut -d "$var4" -f18,19 $i|sort -u`
                var2=$var4""$var3
                sed -n 's/'"$var2"'//p' $i> ./temp/$i
#                sed -e 's/'"$var2"'//p' $i> ./temp/$i
                done

excpected files are passed to temp but with 0 bytes./dm/RMDW_LandingZone/dev/work_area/ABaC_reregister/temp> ls -ltr
total 8
drwxrwxrwx 2 mc25730 dstage 4096 2013-10-15 02:59 renamed_files
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv

i think problem is coming while i pass variable in cut and sed command ..

Could you please show us the result of this :

cd /dm/RMDW_LandingZone/dev/work_area/ABaC_reregister
ls -l | grep GTDA

/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> ls -l | grep GTDA
-rwxrwxrwx 1 mc25730 dstage 242 2013-10-15 04:18 file_GTDA.xls

/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> more file_GTDA.xls
GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv
GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv

---------- Post updated at 03:12 PM ---------- Previous update was at 03:10 PM ----------

:/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> ls -l | grep GTDA
-rw-rw-r-- 1 mc25730 dstage 440 2013-10-15 04:18 file_GTDA1.xls
-rwxrwxrwx 1 mc25730 dstage 242 2013-10-15 04:18 file_GTDA.xls
/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> more file_GTDA.xls
GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv
GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv