Extracting required string from routine's return value

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Extracting required string from routine's return value

Post by ssunda6 »

Hi,

I am executing a shell script which returns value 0 or 1 based on some conditions, using DSExecute function in a routine(transform function)

Ans=Output<1> worked fine and i got the required output.

Because of some error in the script, the script is now returning some error statements along with the return code(0/1) that I want. But I want only the last value (either 0/1) returned from the script whether it executes successfully or not.

How can I extract only the return value from the dynamic output.

Regards,
ssunda
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

Hi,

My issue is resolved.

While using the DSExecute function, I was earlier using

Call DSExecute("UNIX","sh ScriptName",Output,SystemReturnCode)
Ans=Output<1>

Now I tried getting the required output by using awk.

Solution:

Call DSExecute("UNIX","sh ScriptName 2>&1 | awk '{line=$0} END {print line}'",Output,SystemReturnCode)
Ans=Output

awk is acting on the output of sh command. Each record is identified as $0. The block after END will be processed once all the records are processed. So, "line" will contain the last line and I am printing it.

Regards,
ssunda.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not really pretty, and definitely not optimal. Piping through tail -1 (or tail -2 | head -1 if necessary) would have been easier on system resources.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I thought we answered how to do this in another thread? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

Hi ,

After moving this to parallel forum, i dint check the reply you posted to that thread.

Ray,
yes, tail -1 option is better. Thanx

Thank you,
ssunda.
Post Reply