![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Korn: How to zero fill df output so it will sort properly | shew01 | Shell Programming and Scripting | 9 | 06-04-2008 10:34 AM |
| not getting the output properly | pmrajesh21 | SUN Solaris | 0 | 04-16-2008 10:43 AM |
| I can't divide properly in shell | mikez104 | UNIX for Dummies Questions & Answers | 3 | 02-26-2008 05:20 PM |
| How to output the results of the AT command - properly! | SpanishPassion | UNIX for Dummies Questions & Answers | 4 | 12-04-2005 10:27 PM |
| counting lines and showing the output | jjoves | UNIX for Dummies Questions & Answers | 13 | 08-03-2004 09:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi!
Can anyone tell me what went wrong in my shell script? Code:
for dt_val in `cut -f 1 -d '|' /prod/ods/satyaki/sqlldr/grp.dat` do echo $dt_val done Code:
23 39 The time is later! Code:
ods@awhq7154[/prod/ods/satyaki/sqlldr]>cut -f 1 -d '|' grp.dat LX OS FO FO FO IS MO MO MS NI NI NI NI NI OP OP OS OS OS PL UN Thanks in advance for your reply. Regards. |
|
||||
|
I've updated my query to -
Code:
DBCONNECTSTRING=Ual_ods_dev01/1forods@ODS1.WHQ.UAL.COM
#cut -f 1-11 -d '|' /prod/ods/satyaki/sqlldr/grp.dat>grp_out.dat
for val in `cat /prod/ods/satyaki/sqlldr/grp.dat`
do
O_GRP_CD=`echo $val|cut -c 15-16`
echo "O_GRP_CD:" $O_GRP_CD
tmp=`echo $val|cut -c 1-2`
DIV_ID=`sqlplus -s ${DBCONNECTSTRING} <<!
set heading off feedback off verify off
select ops_rsn_div.ops_rsn_div_id from ops_rsn_div where ops_rsn_div.ops_rsn_div_cd = '$tmp';
exit
!`
O_DIV_ID=`echo $DIV_ID | tr -s " " | sed 's/^[ ]//g'`
# echo "O_DIV_ID: " $O_DIV_ID
O_GRP_DESC=`echo $val|cut -c 42-70`
#echo "O_GRP_DESC:" $O_GRP_DESC
O_EFF_DT=`echo $val|cut -c 18-27`
#echo "O_EFF_DT:" $O_EFF_DT
O_EXPRY_DT=`echo $val|cut -c 31-40`
#echo "O_EXPRY_DT:" $O_EXPRY_DT
echo "O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT |"
out="$O_GRP_CD-$O_DIV_ID-$O_GRP_DESC-$O_EFF_DT-$O_EXPRY_DT"
echo $out
echo "***************************************************"
done
Output is - Code:
ods@awhq7154[/prod/ods/satyaki/sqlldr]>test_n.sh O_GRP_CD: LX O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | LX-9-LATE-2003-03-10-2006-03-07 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: CW O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | CW-5-CREW-1970-01-01-2006-03-07 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: CR O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | CR-3-FLIGHT-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | -7--- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: UA O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | UA-3-WEATHER/ATC-2003-03-10-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: WX O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | WX-3-WEATHER/ATC-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: IS O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | IS-6-INFORMATION-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: MC O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | MC-1-AIRCRAFT-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: MS O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | MS-1-OTHER-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | -7--- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: MS O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | MS-4-MISCELLANEOUS-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: CB O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | CB-2-CABIN-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: CS O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | CS-2-CUSTOMER-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: RS O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | RS-2-RAMP-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: SO O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | SO-2-OTHER-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | -7--- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: SP O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | SP-2-STN-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | -7--- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | -8--- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: DI O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | DI-7-DISPATCH-2006-12-05-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: RT O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | RT-7-SYSTEM-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | -7--- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: CR O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | CR-5-CREW-2006-03-08-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: OT O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | OT-5-CATERING-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: SC O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | SC-5-SCHEDULING-2006-03-08-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: PL O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | PL-8-PLANNING-1970-01-01-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: UN O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | UN-10-Unscheduled-2006-03-28-9999-12-31 *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** O_GRP_CD: O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT | ---- *************************************************** Code:
LX|2003-03-10|LX|2003-03-10|Y|2006-03-07|LATE TURN | |N|| OS|1970-01-01|CW|1970-01-01|Y|2006-03-07|CREW |1|N|| FO|1970-01-01|CR|1970-01-01|Y|9999-12-31|FLIGHT OPERATIONS |1|N|| FO|1970-01-01|UA|2003-03-10|Y|9999-12-31|WEATHER/ATC |2|N|| FO|1970-01-01|WX|1970-01-01|Y|9999-12-31|WEATHER/ATC |2|N|| IS|1970-01-01|IS|1970-01-01|Y|9999-12-31|INFORMATION SVCS |1|N|| MO|1970-01-01|MC|1970-01-01|Y|9999-12-31|AIRCRAFT MAINTENANCE |1|N|| MO|1970-01-01|MS|1970-01-01|Y|9999-12-31|OTHER MAINTENANCE OPS |2|N|| MS|1970-01-01|MS|1970-01-01|Y|9999-12-31|MISCELLANEOUS |1|N|| NI|1970-01-01|CB|1970-01-01|Y|9999-12-31|CABIN SERVICE |2|N|| NI|1970-01-01|CS|1970-01-01|Y|9999-12-31|CUSTOMER SERVICE |1|N|| NI|1970-01-01|RS|1970-01-01|Y|9999-12-31|RAMP SERVICE |2|N|| NI|1970-01-01|SO|1970-01-01|Y|9999-12-31|OTHER STATION OPS |5|N|| NI|1970-01-01|SP|1970-01-01|Y|9999-12-31|STN OPS PLANNING |4|N|| OP|1970-01-01|DI|2006-12-05|Y|9999-12-31|DISPATCH |1|N|| OP|1970-01-01|RT|1970-01-01|Y|9999-12-31|SYSTEM OPERATIONS CONTROL |2|N|| OS|1970-01-01|CR|2006-03-08|Y|9999-12-31|CREW |2|N|| OS|1970-01-01|OT|1970-01-01|Y|9999-12-31|CATERING |1|N|| OS|1970-01-01|SC|2006-03-08|Y|9999-12-31|SCHEDULING |3|N|| PL|1970-01-01|PL|1970-01-01|Y|9999-12-31|PLANNING DIVISION |1|N|| UN|1993-01-05|UN|2006-03-28|Y|9999-12-31|Unscheduled Stop |1|N|| Can anyone help me? Thanks in advance for your reply. |
|
||||
|
Hi Satya,
your very first version of code itself should work properly; can you try this... #!'which sh' for dt_val in `cut -f 1 -d '|' /prod/ods/satyaki/sqlldr/grp.dat` do echo $dt_val done I just declared the shell to be used as sh. If this doesn't work...can you tell the OS which you are using and the o/p of "which sh" command? -ilan |
|
||||
|
Thanks a lot for your reply. It is working.
Now, i'm facing another problem. I want to use those value in a insert query. Though, this process fetched data perfectly, but unable to insert it into the table. I've modified my insert script and place it in an anonymous PL/SQL block inside the shell to track the error message. But, unable to get that. Now, my question is - how to track sql error message inside any shell. I'm posting you my latest script - Code:
while IFS='|' read field1 field2 O_GRP_CD O_EFF_DT field5 \
O_EXPRY_DT O_GRP_DESC field8 field9 field10
do
DIV_ID=`sqlplus -s ${DBCONNECTSTRING} <<!
set heading off feedback off verify off
select ops_rsn_div.ops_rsn_div_id
from ops_rsn_div
where ops_rsn_div.ops_rsn_div_cd = '$field1';
exit
!`
O_DIV_ID=`echo $DIV_ID | tr -s " " | sed 's/^[ ]//g'`
# echo "O_GRP_CD|O_DIV_ID|O_GRP_DESC |O_EFF_DT |O_EXPRY_DT |"
out="'${O_GRP_CD}'-${O_DIV_ID}-'${O_GRP_DESC}'-'${O_EFF_DT}'-'${O_EXPRY_DT}'"
DIV_ID2=`sqlplus -s ${DBCONNECTSTRING} <<!
set heading off feedback off verify off
set serveroutput on
begin
insert into ops_rsn_grp values('trim(${O_GRP_CD}'),
ops_rsn_seq.nextval,
trim(${O_DIV_ID}),
'${O_GRP_DESC}',
to_date(trim('${O_EFF_DT}'),'YYYY-MM-DD'),
to_date(trim('${O_EXPRY_DT}'),'YYYY-MM-DD'),
to_timestamp(to_char(systimestamp,'DD-MM-YYYY HH24:MI:SS.FF'),
'DD-MM-YYYY HH24:MI:SS.FF'),
null);
commit;
exception
when others then
dbms_output.put_line(sqlerrm);
end;
exit
!`
echo "Bug: " $DIV_ID2
echo $out
echo "***************************************************"
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|