For loop using LABEL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop using LABEL
# 1  
Old 10-18-2013
For loop using LABEL

Hi,

i have below code so i want to run only one for loop instead of two.

Code:
if [ $SLS_COUNT -gt 0 ]; then
                FILE_NAME_SLS=`cat $FILE_PATH|grep 'GTDA_Dly_Sls_'`
                DELMT="|"
                for i in $FILE_NAME_SLS
                do
                ABaC_COL_SL=`cut -d "$DELMT" -f18,19 "$i"|sort -u`
                RM_ABaC_COL_SL=$DELMT""$ABaC_COL_SL
                sed -n 's/'"$RM_ABaC_COL_SL"'//p' $i> $WORK_AREA_PATH/TDA_FILES/$i
                done
                echo " GTDA sales done"
fi

if [ $PMIX_COUNT -gt 0 ]; then
                FILE_NAME_PMIX=`cat $FILE_PATH|grep 'GTDA_Dly_Pmix_'`
                DELMT="|"
                for i in $FILE_NAME_PMIX
                do
                ABaC_COL_PM=`cut -d "$DELMT" -f12,13 "$i"|sort -u`
                RM_ABaC_COL_PM=$DELMT""$ABaC_COL_PM
                sed -n 's/'"$RM_ABaC_COL_PM"'//p' $i> $WORK_AREA_PATH/TDA_FILES/$i
                done
                echo " GTDA Pmix done"
fi

Thanks in advance!!!

Last edited by Scrutinizer; 10-18-2013 at 08:29 AM.. Reason: changed icode tags to regular code tags
# 2  
Old 10-18-2013
Quote:
Originally Posted by renuk
Hi,

i have below code so i want to run only one for loop instead of two.

Code:
if [ $SLS_COUNT -gt 0 ]; then
                FILE_NAME_SLS=`cat $FILE_PATH|grep 'GTDA_Dly_Sls_'`
                DELMT="|"
                for i in $FILE_NAME_SLS
                do
                ABaC_COL_SL=`cut -d "$DELMT" -f18,19 "$i"|sort -u`
                RM_ABaC_COL_SL=$DELMT""$ABaC_COL_SL
                sed -n 's/'"$RM_ABaC_COL_SL"'//p' $i> $WORK_AREA_PATH/TDA_FILES/$i
                done
                echo " GTDA sales done"
fi

if [ $PMIX_COUNT -gt 0 ]; then
                FILE_NAME_PMIX=`cat $FILE_PATH|grep 'GTDA_Dly_Pmix_'`
                DELMT="|"
                for i in $FILE_NAME_PMIX
                do
                ABaC_COL_PM=`cut -d "$DELMT" -f12,13 "$i"|sort -u`
                RM_ABaC_COL_PM=$DELMT""$ABaC_COL_PM
                sed -n 's/'"$RM_ABaC_COL_PM"'//p' $i> $WORK_AREA_PATH/TDA_FILES/$i
                done
                echo " GTDA Pmix done"
fi

Thanks in advance!!!

Use CODETAG not ICODE

write one function and call it

something like this

Code:
Fun_foo(){
                for i in $1
                do
                               you code goes here................
                               .................................
                               .................................
                done
         }

Code:
foo(){
              DELMT="|"
              for i in $1; 
                do
                    ABaC_COL_SL=`cut -d "$DELMT" -f18,19 "$i"|sort -u`
                    RM_ABaC_COL_SL=$DELMT""$ABaC_COL_SL
                    sed -n 's/'"$RM_ABaC_COL_SL"'//p' $i> $WORK_AREA_PATH/TDA_FILES/$i
               done
     }

if [ $SLS_COUNT -gt 0 ]; then
    FILE_NAME_SLS=`cat $FILE_PATH|grep 'GTDA_Dly_Sls_'`
    foo $FILE_NAME_SLS
    echo " GTDA sales done"
fi

if [ $PMIX_COUNT -gt 0 ]; then
    FILE_NAME_PMIX=`cat $FILE_PATH|grep 'GTDA_Dly_Pmix_'`
    foo $FILENAME_PMIX
    echo " GTDA Pmix done"
fi


Last edited by Akshay Hegde; 10-18-2013 at 08:33 AM..
This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 10-18-2013
What is the content of the file referred to by $FILE_PATH ?
# 4  
Old 10-18-2013
But columns in both the for are different in one for i am removing 18,19 and in other for i am removing 12,13...so how can i use same for for both...

---------- Post updated at 05:22 PM ---------- Previous update was at 05:16 PM ----------

FILE_PATH is just the path of file unmacthed.dat file which contains lis of files in it...from which the code will search pattern accordingly.
# 5  
Old 10-18-2013
Yes, could you give a sample of "unmacthed.dat"?
# 6  
Old 10-18-2013
more GTDA_UNMATCHED_FILES.dat
Code:
GTDA_Dly_Pmix_ES_140_20131001.20131018025152.psv
GTDA_Dly_Pmix_ES_140_20131001.20131018025154.psv
GTDA_Dly_Pmix_ES_140_20131001.20131018025156.psv
GTDA_Dly_Sls_ES_140_20131001.20131018025218.psv
GTDA_Dly_Sls_ES_140_20131001.20131018025220.psv


Last edited by Scrutinizer; 10-18-2013 at 09:11 AM.. Reason: code tags
# 7  
Old 10-18-2013
Quote:
Originally Posted by renuk
But columns in both the for are different in one for i am removing 18,19 and in other for i am removing 12,13...so how can i use same for for both...
You can pass the field numbers as parameters as well.

Updating Ashkay's solution:
Code:
foo(){
              DELMT="|"
              for i in $1; 
                do
                    ABaC_COL_SL=`cut -d "$DELMT" -f$2,$3 "$i"|sort -u`
                    RM_ABaC_COL_SL=$DELMT""$ABaC_COL_SL
                    sed -n 's/'"$RM_ABaC_COL_SL"'//p' $i> $WORK_AREA_PATH/TDA_FILES/$i
               done
     }

if [ $SLS_COUNT -gt 0 ]; then
    FILE_NAME_SLS=`cat $FILE_PATH|grep 'GTDA_Dly_Sls_'`
    foo "$FILE_NAME_SLS" 18 19
    echo " GTDA sales done"
fi

if [ $PMIX_COUNT -gt 0 ]; then
    FILE_NAME_PMIX=`cat $FILE_PATH|grep 'GTDA_Dly_Pmix_'`
    foo "$FILE_NAME_PMIX" 12 13
    echo " GTDA Pmix done"
fi

EDIT: Given that $FILE_NAME_xxxx appears to be a list, you'll need to quote it when calling the function.

Last edited by CarloM; 10-18-2013 at 11:17 AM..
This User Gave Thanks to CarloM For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Which IP label is used for HeartBeating?

Hi, In HACMP, which IP label ( Service/ Boot/ Persisten) is used for send/receive Heartbeat packets in IP based Heartbeating? (1 Reply)
Discussion started by: ksgnathan
1 Replies

2. UNIX for Dummies Questions & Answers

How to read a disk label?

Hi there, I'm wondering how to display a disk label (why not edit it but I don't need that yet). I found several commands on forums like disklabel and diskinfo but I can't find them on my system and don't know the package they belong to. Can you help me? Cheers Santiago (2 Replies)
Discussion started by: chebarbudo
2 Replies

3. Solaris

Help:"Bad checksum in disk label" and "Can't open disk label package"?

Hello, I'm brand new to Sun/Solaris. I have a Sun Blade 150, with SunOS 5.8. I wanted to make a backup to prevent future data loss, so I put the disk in a normal PC with Windows XP to try to make a backup with Norton Ghost, the disk was detected, but not the file volume, so I place the disk... (6 Replies)
Discussion started by: Resadija
6 Replies

4. Shell Programming and Scripting

Using A Goto Label?

Im trying to do something like this but I cant find any documentation. read X if then goto ThisLine fi OTHER CODE OTHER CODE Label: ThisLine echo "You entered 1" (5 Replies)
Discussion started by: Grizzly
5 Replies

5. UNIX for Advanced & Expert Users

how to write volume label / ID into CD

I've a peculiar requirement that, i want to write the md5sum of the ISO image in to CD or DVD where i write that ISO. If you want to write some other information as volume label/ID, we can use the mkisofs command's -V option. But i cannot use this because before the creation of the iso file,... (0 Replies)
Discussion started by: thegeek
0 Replies

6. AIX

Label: Fcp_array_err4

In errpt i have got the following error and my database performs slow. --------------------------------------------------------------------------- LABEL: FCP_ARRAY_ERR4 IDENTIFIER: D5385D18 Date/Time: Tue Jul 22 10:50:10 CUT Sequence Number: 193913 Machine Id: ... (1 Reply)
Discussion started by: vjm
1 Replies

7. HP-UX

Label printing help

Hi I need some help in label printing with Zebra printers. (Model 220xiII) Here is a small test label file which prints fine in portrait format. Can anyone tell me how to change the label printing mode to landscape format? HEADER;TESTLBL;1;1;5;4... (0 Replies)
Discussion started by: rpalghat
0 Replies

8. AIX

Label: Disk_err4

I was trying to access my filesystem "tools" but couldn't, so I run fsck, but says Unable to read superblock (TERMINATED) when try mounting says mount: /dev/lv01 on /tools: I/O error the state of logical volumes of rootvg are "open/stale", what does it means? LV NAME TYPE ... (4 Replies)
Discussion started by: andwhat
4 Replies

9. AIX

Label:scan_error_chrp

Am getting an error in error log LABEL: SCAN_ERROR_CHRP IDENTIFIER: BFE4C025 Date/Time: Wed May 17 10:49:32 CUT Sequence Number: 6738 Machine Id: 00CD552E4C00 Node Id: dbs104 Class: H Type: PERM Resource Name: sysplanar0 Resource Class:... (0 Replies)
Discussion started by: vjm
0 Replies

10. UNIX for Dummies Questions & Answers

Solaris 8 label command

I have a RAID 5 set that is 100GB. i recently added more disks to the RAID so its now 225GB. In order for Solaris to recognize the new disk size i was told to lable the disk again. the disk is under Veritas Vol Mgr and File Sys control will i lose data if i do this? (3 Replies)
Discussion started by: justalogin01
3 Replies
Login or Register to Ask a Question