Sponsored Content
Top Forums Shell Programming and Scripting Shell scripting looping issue Post 303007457 by swathi reddy1 on Thursday 16th of November 2017 11:29:12 PM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 12:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy