Shell scripting looping issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting looping issue
# 1  
Old 11-17-2017
Shell scripting looping issue

Code:
#!bin/ksh


---------------------------------------------------------------------------------------------
--                                      Get sequence number from database 
---------------------------------------------------------------------------------------------

.os rm ${BASE_DIRECTORY}/datain/mediation_edm/landing/getsequence.txt 
.export file ${BASE_DIRECTORY}/datain/mediation_edm/landing/getsequence.txt

SELECT MIN(data_file_name)(TITLE '') FROM ${CTLFW_VIEW_DB}.CTLFW_SYSTEM_FILE_EXTRACT WHERE CTL_ID=690 AND BUSINESS_DATE ge DATE-31 AND FILE_ID =88;
.IF ACTIVITYCOUNT <> 1 THEN SELECT MAX(data_file_name)(TITLE '') FROM ${CTLFW_VIEW_DB}.CTLFW_SYSTEM_FILE_EXTRACT WHERE CTL_ID=690 AND BUSINESS_DATE lt DATE-31 AND FILE_ID =88;
.IF ACTIVITYCOUNT <> 1 THEN QUIT 1
.export reset
.logoff
.quit 0
!!END!!

Mediation_MSC_TO_VODA12_Daily()
{
set -x
DataFileName=$(awk 'NR == 1 { print; exit 0 }' getsequence.txt)
SequenceNum=${DataFileName:23:8}
for file in `ls`
do
if test ${file:21:2} -gt 10;
then
ServerNumber=01
IncSequence="$((SequenceNum=SequenceNum+1))"
PaddedSequence=$IncSequence
while [[ $(echo -n ${PaddedSequence} | wc -c) -lt 8 ]] ; do
    PaddedSequence="0${PaddedSequence}"
done
new=${file:0:21}$ServerNumber$PaddedSequence${file:31:4} 
mv $file $new
fi
done
}

show_menus() {
    clear
    echo "~~~~~~~~~~~~~~~~~~~~~"    
    echo " Flow Number Menu"
    echo "~~~~~~~~~~~~~~~~~~~~~"
    echo "Select the number to replace name of the flow"
    echo "1. Mediation_MSC_TO_VODA12_Daily"
    echo "2. Mediation_MTAS_TO_VODA12_Daily"
    echo "3. Mediation_SMS_TO_VODA12_Daily"
    echo "4. Mediation_EPGW_PCDR_to_VODA12_Daily"
    echo "5. Mediation_ESGSN_SCDR_to_VODA12_Daily"
    echo "6. Mediation_ESGW_SCDR_to_VODA12_Daily"
    echo "7. MediationOR_To_Voda12_Daily"
    echo "8. Exit"
}

read_options(){
    echo "Enter choice [ 1 - 8] "
    read choice    
    case $choice in
        1) Mediation_MSC_TO_VODA12_Daily ;;
        2) two ;;
        3) three ;;
        4) four ;;
        5) five ;;
        6) six ;;
        7) seven ;;
        8) exit 0;;
        *) echo -e "Enter a Valid Input"
    esac
}

show_menus
read_options

The above code loops for each file ,but i want to loop for every 2 files shown below

---------- Post updated at 11:29 PM ---------- Previous update was at 10:09 PM ----------

Code:
E_MSC_EKMS1_20160501_1100000001.dat E_MSC_EKMS1_20160501_1100000001.ctl
  E_MSC_EKMS1_20160501_1200000001.dat E_MSC_EKMS1_20160501_1200000001.ctl
  E_MSC_EKMS1_20160501_1300000001.dat E_MSC_EKMS1_20160501_1300000001.ctl

the above files should be renamed to
Code:
E_MSC_EKMS1_20160501_0100000005.dat
E_MSC_EKMS1_20160501_0100000005.ctl

E_MSC_EKMS1_20160501_0100000004.dat
E_MSC_EKMS1_20160501_0100000004.ctl

E_MSC_EKMS1_20160501_0100000003.dat
E_MSC_EKMS1_20160501_0100000003.ctl

Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, output, and code segments (as required by forum rules).

Last edited by Don Cragun; 11-17-2017 at 02:49 AM.. Reason: Put missing CODE tags and moderators comments back in.
# 2  
Old 11-17-2017
There are lots of missing pieces of information that are crucial if you want us to help you:
  1. What operating system are you using?
  2. How is your script supposed to determine which pairs of files you want to process?
  3. After running your database query, what is the format of the contents of getsequence.txt?
  4. What files are present in the directory in which this script will be run?
  5. Are we correct in assuming that you are only interested in what happens when the user types in 1 when read_options runs?
# 3  
Old 11-17-2017
Hi Don,

Thanks for your response

1)we are using unix

3)getsequence.txt will contain format like 'E_MSC_EKMS1_20171013_0100127269.dat'
4)these are the files in my directory

Code:
E_MSC_EKMS1_20160501_1100023455.dat
E_MSC_EKMS1_20160501_1100023455.ctl

E_MSC_EKMS1_20160501_1100023456.dat
E_MSC_EKMS1_20160501_1100023456.ctl

E_MSC_EKMS1_20160501_1100023457.dat
E_MSC_EKMS1_20160501_1100023457.ctl

they need to be renamed like

Code:
E_MSC_EKMS1_20160501_0100000005.dat
E_MSC_EKMS1_20160501_0100000005.ctl

E_MSC_EKMS1_20160501_0100000004.dat
E_MSC_EKMS1_20160501_0100000004.ctl

E_MSC_EKMS1_20160501_0100000003.dat
E_MSC_EKMS1_20160501_0100000003.ctl

5)yes when user types 1

Last edited by Don Cragun; 11-17-2017 at 02:51 AM.. Reason: Add CODE tags again.
# 4  
Old 11-17-2017
Quote:
Originally Posted by swathi reddy1
Hi Don,

Thanks for your response

1)we are using unix

3)getsequence.txt will contain format like 'E_MSC_EKMS1_20171013_0100127269.dat'
4)these are the files in my directory

Code:
E_MSC_EKMS1_20160501_1100023455.dat
E_MSC_EKMS1_20160501_1100023455.ctl

E_MSC_EKMS1_20160501_1100023456.dat
E_MSC_EKMS1_20160501_1100023456.ctl

E_MSC_EKMS1_20160501_1100023457.dat
E_MSC_EKMS1_20160501_1100023457.ctl

they need to be renamed like

Code:
E_MSC_EKMS1_20160501_0100000005.dat
E_MSC_EKMS1_20160501_0100000005.ctl

E_MSC_EKMS1_20160501_0100000004.dat
E_MSC_EKMS1_20160501_0100000004.ctl

E_MSC_EKMS1_20160501_0100000003.dat
E_MSC_EKMS1_20160501_0100000003.ctl

5)yes when user types 1
The way to tell us what operating system you're using is to show us the output from the command uname -a.

If I understand your code correctly (and I am not sure that I do), if the first line of the contents of getsequence.txt is:
Code:
E_MSC_EKMS1_20171013_0100127269.dat

where did the IncSequence values 5, 4, and 3 come from??? Shouldn't the files be renamed as follows?:
Code:
Old name:				New name:
===================================	===================================
E_MSC_EKMS1_20160501_1100023455.ctl	E_MSC_EKMS1_20160501_0100127270.ctl
E_MSC_EKMS1_20160501_1100023455.dat	E_MSC_EKMS1_20160501_0100127270.dat
E_MSC_EKMS1_20160501_1100023456.ctl	E_MSC_EKMS1_20160501_0100127271.ctl
E_MSC_EKMS1_20160501_1100023456.dat	E_MSC_EKMS1_20160501_0100127271.dat
E_MSC_EKMS1_20160501_1100023457.ctl	E_MSC_EKMS1_20160501_0100127272.ctl
E_MSC_EKMS1_20160501_1100023457.dat	E_MSC_EKMS1_20160501_0100127272.dat

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting - CHMOD issue

Hi Friends , good morning . I am very new to Unix scripting and require a bit of advice to help resolve the below issue . Hope some one can provide some suggestion I have the below script which calls a Oracle stored procedure which inturn extracts data from a table and writes in a ascii... (4 Replies)
Discussion started by: J1nx007
4 Replies

2. Shell Programming and Scripting

Issue with looping

Hi guys, I am creating a script that checks if a service is UP and running on a bunch of remote servers. My list of servers is: p2 runtime1 8080 p3 runtime2 8080 p4 runtime3 8080 p5 runtime4 8080 p6 runtime5 8080 p7 runtime6 8080 p8 runtime7 8080 p9 runtime8 8080 p10 runtime9 8080... (4 Replies)
Discussion started by: Junaid Subhani
4 Replies

3. Shell Programming and Scripting

Shell scripting issue-running the background script

I have written the below query to genrate a telephone.I am passing account number from oracle database. I am calling 2 scripts which generate the bill 1. bip.sh (it runs in the background) 2.runXitInvoice_PROFORMA_integ bip.sh generates a number which runXitInvoice_PROFORMA_integ uses.How... (7 Replies)
Discussion started by: rafa_fed2
7 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripting Issue

Hi I have a requirement where in I need to check 103,104,105 letters in each line and if it equal to MAS then I need to copy the whole line (Till End) to a file. In case if there are 10 lines, all these lines must be copied to a file. Can you please help me with script. (1 Reply)
Discussion started by: krishna87
1 Replies

5. Shell Programming and Scripting

Shell Scripting Issue

Hi I have a requirement where in I need to check 103,104,105 letters in each line and if it equal to MAS then I need to copy the whole line (Till End) to a file. In case if there are 10 lines, all these lines must be copied to a file. Can you please help me with script. (1 Reply)
Discussion started by: krishna87
1 Replies

6. Shell Programming and Scripting

Sql issue in shell scripting

HI friends , i am also facing an issue in mysql i ma trying to insert detail in a variable but not got success #!/bin/sh mysql -u<username> -p<password> <dbname> << EOF DEV=`mysql --skip-column-names <dbname> -e "SELECT timestamp from process_record where id = 1"` EOF echo $DEV ERROR... (3 Replies)
Discussion started by: sanjay833i
3 Replies

7. Shell Programming and Scripting

Sftp in shell Scripting issue

I have the below code for ftping a file sftp "ogl@serverna,me"ogl@serverna,me <<EOF cd $path_on_the_server binary put $path_on_my_sever/filename.txt bye EOF Not sure is this works.but when i tried its asking for password .How i can avoid asking password and provide it in the... (5 Replies)
Discussion started by: shyamrad
5 Replies

8. Shell Programming and Scripting

Help with looping in shell scripting

Hi there im totally new to shell scripting and i find it very interesting. I come from java programming background. Basically what i need is to loop a string of say all possible permutations of 20 displayable characters and md5 hash the string till it produces a 128 bit hash value with say 4... (17 Replies)
Discussion started by: jremio
17 Replies

9. Shell Programming and Scripting

[Solved] help me in this looping in shell scripting

Hi, #!/bin/ksh result='/TIA/app/UniQP/queue/document/CSB' i=0; while ; do i=`expr $i + 1` if ($i -lt 5);then echo "THerrFile_$i.err"; else break; fi done ... (0 Replies)
Discussion started by: sudhir_83k
0 Replies

10. Shell Programming and Scripting

Issue with Shell Scripting..

Hi Guys.. I need a solution for these two questions... Plz help me... 1)How can you load multiple files in a script ? 2)How do you get a process Id for multiple files in a shell script ? (3 Replies)
Discussion started by: mraghunandanan
3 Replies
Login or Register to Ask a Question