loop going beyond records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop going beyond records
# 1  
Old 04-08-2009
loop going beyond records

sql1="select date_type, offset, mail_list, reminder_offset from osr_cbb_offset_dates"
$JAVA icoredp.tools.oracleUnload -c ${CSORDHOME}/conf -s "$sql1" >> ${output}
NO_OF_REC=`wc -l ${output}| cut -c1-9`
echo "Records in first sql $NO_OF_REC"
cut -f1 $output| while read LINE1
i=0;
do
echo "in first loop"
DATE_TYPE=`echo $LINE1|cut -f1 -d "|"`
OFFSET=`echo $LINE1|cut -f2 -d "|"`
MAIL_LIST=`echo $LINE1|cut -f3 -d "|"`
REMINDER_OFFSET=`echo $LINE1|cut -f4 -d "|"`





sql2="Select unique P.project_id, project_title, location_clli, prem_city, prem_state, OSR1.ptnii_equip_name, OSR2.ptnii_equip_name, Planner.name, Planner.phone, PM.name, PM.phone, date_type, mail_list,P.$DATE_TYPE
From voip_project P, voip_project_det D, equipment OSR1, equipment OSR2, planners_and_pms Planner, planners_and_pms PM, osr_cbb_offset_dates, ip_complex
Where P.project_id = D.project_id
And ip_complex.clli = P.location_clli
And D.equip_id_1 = OSR1.equip_id
And D.equip_id_2 = OSR2.equip_id
And P.planner_id = Planner.plpm_id
And P.pm_id = PM.plpm_id
And date_type = '$DATE_TYPE'
and P.STATUS != 'WITHDRAWN'
and to_char(P.$DATE_TYPE - nvl('0',0),'MM/DD/YYYY')=to_char(sysdate,'MM/DD/YYYY')"

$JAVA icoredp.tools.oracleUnload -c ${CSORDHOME}/conf -d "," -s "$sql2" > ${DISCORDFILE}
NO_OF_RECORDS=`wc -l ${DISCORDFILE}| cut -c1-9`
echo "Records in 2nd sql $NO_OF_RECORDS"
if [ $NO_OF_RECORDS -eq 0 ]; then
echo "No Records found for Service"

else
cut -f1 $DISCORDFILE| while read LINE1

do
echo "in 2nd loop"
PROJECT_ID=`echo $LINE1|cut -f1 -d ","`
PROJECT_TITLE=`echo $LINE1|cut -f2 -d ","`
PREM_CITY=`echo $LINE1|cut -f4 -d ","`
PREM_STATE=`echo $LINE1|cut -f5 -d ","`
OSR1=`echo $LINE1|cut -f6 -d ","`
OSR2=`echo $LINE1|cut -f7 -d ","`
PLANNER_NAME=`echo $LINE1|cut -f8 -d ","`
PLANNER_PHONE=`echo $LINE1|cut -f9 -d ","`
PM_NAME=`echo $LINE1|cut -f10 -d ","`
PM_PHONE=`echo $LINE1|cut -f11 -d ","`
DATE_TYPE=`echo $LINE1|cut -f12 -d ","`
MAIL_LIST1=`echo $LINE1|cut -f13 -d ","`
DATE_OF_PROJECT=`echo $LINE1|cut -f14 -d ","`

echo "value of i is $i"
PROJECT_ID_array[$i]=$PROJECT_ID;
echo ${PROJECT_ID_array[$i]}
PREM_CITY_array[$i]=$PREM_CITY;
PREM_STATE_array[$i]=$PREM_STATE;
PROJECT_TITLE_aray[$i]=$PROJECT_TITLE;
DATE_OF_PROJECT_array[$i]=$DATE_OF_PROJECT;
DATE_TYPE_array[$i]=$DATE_TYPE;
PLANNER_NAME_array[$i]=$PLANNER_NAME;
PLANNER_PHONE_array[$i]=$PLANNER_PHONE;
PM_NAME_array[$i]=$PM_NAME;
PM_PHONE_array[$i]=$PM_PHONE;
OSR1_array[$i]=$OSR1;
echo ${OSR1_array[$i]}
OSR2_array[$i]=$OSR2;
echo ${OSR2_array[$i]}

i=$((i+1))
done


echo records for 2nd value is ${PROJECT_ID_array[1]}
fi
done

"in the above code SQL 1 generates 9 records...so the outer loop should continue for 9 records bt it is going beyond 9..."
# 2  
Old 04-09-2009
It's a bit hard to tell without any of the debugging output that this would generate,
but there are a couple of small things to check:

You have this on the second line to create the output file which feeds the loop :
$JAVA icoredp.tools.oracleUnload -c ${CSORDHOME}/conf -s "$sql1" >> ${output}
You use ">>" and APPEND to $output, so if this was attempted more than once,
there could be more than 9 lines it $output.


Depending on your shell, it might be unwise to have BOTH while loops use the same variable:

cut -f1 $output| while read LINE1
cut -f1 $DISCORDFILE| while read LINE1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate records of a file on 2 types of records

Hi I am new to shell programming in unix Please if I can provide help. I have a file structure of a header record and "N" detail records. The header record will be the total number of detail records I need to split the file in 2: One for the header Another for all detail records Could... (1 Reply)
Discussion started by: jamcogar
1 Replies

2. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

3. Shell Programming and Scripting

File 1 Column 1 value search in File 2 records, then loop?

Summary: I planned on using Awk to grab a value from File 1 and search all records/fields in file 2. If there is a match in File 2, print the first column value of the record of the match of File2. Continue this search until the end of file 2. Once at the end of file 2, grab the next value in... (4 Replies)
Discussion started by: Incog
4 Replies

4. Shell Programming and Scripting

parallel while loop based on the file records

Hi, I need to execute parallel with while loop. Input File(source_file.csv) contains filenames the below source_file.csv file contains Customer1.txt Product1.txt Sales.txt Emp.txt Dept.txt Based on the number of rows that file I want to run the script ‘n' times. while... (2 Replies)
Discussion started by: onesuri
2 Replies

5. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

6. Shell Programming and Scripting

Push records to array during implicit loop and write to file

NEWBIE ALERT! Hi, I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies

7. Shell Programming and Scripting

Based on num of records in file1 need to check records in file2 to set some condns

Hi All, I have two files say file1 and file2. I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions . Could you pls... (3 Replies)
Discussion started by: mavesum
3 Replies

8. AIX

loop records

Initially i store some files into anothe file Y. Now i want read the contents of file Y one by one do some check on each file. i,e Open file Y (contains multiple files) First read a file , do some check on that individual file.If that file satisfies teh condition put it in another file. Now... (1 Reply)
Discussion started by: vasuarjula
1 Replies

9. Shell Programming and Scripting

loop number of records.

Initially i store some files into anothe file Y. Now i want read the contents of file Y one by one do some check on each file. i,e Open file Y (contains multiple files) First read a file , do some check on that individual file.If that file satisfies teh condition put it in another file. Now... (1 Reply)
Discussion started by: vasuarjula
1 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question