Output in my shell isn't showing properly.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output in my shell isn't showing properly.
# 1  
Old 03-31-2008
Network Output in my shell isn't showing properly.

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

And, the output is -

Code:

23
39
The time is later!

But, when i run this code prompt shell prompt - it is giving me my desired result -

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

What is the reason?

Thanks in advance for your reply.

Regards.
# 2  
Old 03-31-2008
Anyone have any idea?
# 3  
Old 03-31-2008
For your information i would like to add another thing -

My data file format is as follows -

Code:
LX|KKK|LO|1|23-DEC-2007

Regards
# 4  
Old 03-31-2008
Network

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

But, it is not showing the proper output.

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

Whereas the data is -

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

What went wrong here?

Can anyone help me?

Thanks in advance for your reply.
# 5  
Old 03-31-2008
Try the following new version of your script :
Code:
DBCONNECTSTRING=Ual_ods_dev01/1forods@ODS1.WHQ.UAL.COM

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"

    echo $out

    echo "***************************************************"

done < /prod/ods/satyaki/sqlldr/grp.dat

Jean-Pierre.

Last edited by aigles; 03-31-2008 at 02:17 PM.. Reason: Test code (for DIV_ID) removed
# 6  
Old 03-31-2008
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
# 7  
Old 04-01-2008
Network

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 "***************************************************"

Thanks again in advance for your reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pgrep not showing desired output

I am searching for a process that should be up and running. Im using the following command ps -ef | grep elasticsearch to get elastic+ 1673 1 0 Jan29 ? 05:08:56 /bin/java -Xms4g -Xmx4g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

2. UNIX for Dummies Questions & Answers

Command showing no output!

Hi Folks, I have a situation here, where no command is giving any output, and it's not even showing any error message also. What could be the reason? (3 Replies)
Discussion started by: nixhead
3 Replies

3. Shell Programming and Scripting

Now showing the correct output

Hello I am working on one script where I am trying to display all the directories which is inside the workspace but somehow it is giving me weird output and this is occurring only with one directory other also having the result.html file inside the directory. for i in `ls -1 | egrep -iv... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

4. Solaris

Showing strange size in df output

Hi, This is Solaris-10 box and in few of file-system (root file-system of non global zones), usage/available is not showing correct size. I am not able to figure out, what is eating up this space. Global Server - bdrpod01 Non Global zone - bdrpod01-zputq01 root@bdrpod01:/root# df -h... (2 Replies)
Discussion started by: solaris_1977
2 Replies

5. Shell Programming and Scripting

shell script, why isn't if printing message?

Why isn't printing message? 1 #!/bin/sh 2 3 something(){ 4 echo "Inside something" 5 echo $1 $2 6 } 7 val=$(something "Hello " "world") But it prints. 1 #!/bin/sh 2 3 something(){ 4 echo "Inside something" 5 echo $1 $2 6 } 7... (4 Replies)
Discussion started by: cola
4 Replies

6. UNIX for Dummies Questions & Answers

Isn't a shell found on a beach? Need help nesting if's or loops.

As of a week ago i thought a shell was somthing found on a beach. I'm a virgin when it comes to scripting and i'm having a really bad time here. What i need to do is prompt for a group number grep the /etc/groups to get the GID and name if it exists i want to prompt the user for... (3 Replies)
Discussion started by: switchkill
3 Replies

7. Shell Programming and Scripting

Korn: How to zero fill df output so it will sort properly

I'm looking for a way in Korn shell to zero fill (or space fill) the output from df so that it will sort properly. "Raw" output from df -k: df -k Filesystem kbytes used avail capacity Mounted on /dev/vx/dsk/rootvol 4131866 3593302 497246 88% / /proc ... (9 Replies)
Discussion started by: shew01
9 Replies

8. Solaris

not getting the output properly

i am entering the command, not get the total out put see the output what i am getting. SQL> select dbms_metadata.get_ddl ('TABLESPACE','SYSTEM') FROM DUAL; DBMS_METADATA.GET_DDL('TABLESPACE','SYSTEM') -------------------------------------------------------------------------------- ... (0 Replies)
Discussion started by: pmrajesh21
0 Replies

9. UNIX for Dummies Questions & Answers

How to output the results of the AT command - properly!

Hi, I am new to UNIX and I am more used to simple commands like those in VMS. One of them is the ability to get the output from a job using the /out=<file> command in VMS. I want to submit a job (a set of unix commands) using the AT command but to get the output in a file like that used in... (4 Replies)
Discussion started by: SpanishPassion
4 Replies
Login or Register to Ask a Question