Cut command not working in for loop | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Cut command not working in for loop

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-15-2013
renuk renuk is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 1 April 2014, 2:05 AM EDT
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Cut command not working in for loop


Code:
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:

Code:
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!!!

Last edited by vbe; 10-15-2013 at 05:15 AM.. Reason: rm HTML...
Sponsored Links
    #2  
Old 10-15-2013
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 10 October 2014, 7:04 AM EDT
Location: ./India/Banglore
Posts: 1,207
Thanks: 53
Thanked 270 Times in 263 Posts
Hi Renuk,

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

Thanks
Pravin
Sponsored Links
    #3  
Old 10-15-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 28 October 2014, 9:25 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
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.

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

    #4  
Old 10-15-2013
renuk renuk is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 1 April 2014, 2:05 AM EDT
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
@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
Sponsored Links
    #5  
Old 10-15-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 28 October 2014, 9:25 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
What output you have passing these commands ?

Code:
$ 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
Sponsored Links
    #6  
Old 10-15-2013
renuk renuk is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 1 April 2014, 2:05 AM EDT
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
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 ..
Sponsored Links
    #7  
Old 10-15-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 28 October 2014, 9:25 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
Could you please show us the result of this :


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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cut Command error cut: Bad range dgmm Shell Programming and Scripting 2 05-22-2011 01:56 PM
cut not working the way i want it to ShinTec UNIX for Dummies Questions & Answers 8 01-20-2011 03:12 AM
cut the present working directory Reddy482 Shell Programming and Scripting 1 11-12-2009 07:05 PM
Cut not working in a loop KME UNIX for Dummies Questions & Answers 4 11-05-2009 04:59 PM
Use loop var i within Cut Command de_la_espada Shell Programming and Scripting 3 07-10-2009 04:30 AM



All times are GMT -4. The time now is 10:13 AM.