Getting a First line of a text file from UNIX to Datastage

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
trammohan
Participant
Posts: 47
Joined: Thu Nov 13, 2003 12:47 pm

Getting a First line of a text file from UNIX to Datastage

Post by trammohan »

Hi ,

Is there any way to get the first line of a text file from UNIX to Datastage
Client
I tried in this way

[b]return `head -1 /home/apps/z602376/junk/REP_HisKey.txt`

from Execute command activity[/b].. If the value is more than 128 ..( 1 byte limitation ) it is not returning correct value..

Thanks

Ram
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

I think you are trying to jam the output text into the Return Code field instead of the output field. The DSExecute command returns two fields:
Call DSExecute (ShellType, Command, Output, SystemReturnCode)

The SystemReturnCode should be used to hold the status of the command with 0 indicating success. The Output field holds everything echoed by the command.

Code: Select all

UnixCMD = "head -1 /home/apps/z602376/junk/REP_HisKey.txt"
Call DSExecute("UNIX", UnixCMD, Output, RetCode)
This should put the output of the head command into the Output field. For a more robust option create a Unix script that checks that the file exists and returns a failure code if it is not found.[/b]
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How exactly do you want to use this one line in your job sequence? I note that you specified a Routine Activity. If you use a Routine that incorporates code like that Vincent suggested, make sure that the value of the Output argument is assigned to the return variable (Ans).

Your syntax does not work in the routine name field of a Routine Activity. What you actually need here is the name of a Routine that is in your Repository. On the Routines tab, choose your routine from the drop down list of routine names; you will have needed already to have created and compiled a Routine (whose type is Transform Function).

Here's a sample Routine.

Code: Select all

FUNCTION GetFirstLineFromFile(FileName)

* Set up arguments for subroutine call.
Shell = "UNIX"
Command = "head -1 " : FileName
Output = ""
Code = 0

Call DSExecute(Shell, Command, Output, Code)

* Code = 0 indicates successful execution.
If Code = 0
Then
   Ans = Trim(Trim(Output, @FM, "A"))
End
Else
   Ans = ""
   @User0 = Code  ; * can be detected in caller
End

RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
trammohan
Participant
Posts: 47
Joined: Thu Nov 13, 2003 12:47 pm

Post by trammohan »

Thanks Ray & Vincent

Ram Thota
Post Reply