Command execute activity

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Command execute activity

Post by mydsworld »

Has anyone used 'wc -l <filename>' in 'Execute Command' activity stage.

the output I am getting is :

10 <filename>

However, I expect :

10

i have used :

command : wc
Parameters : -l <filename>

Is it correct .
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Your expectations are wrong as you'll always get the filename after the count. Use 'cut' or some other mechanism to separate the count from the filename before it gets passed back out.
-craig

"You can never have too many knives" -- Logan Nine Fingers
visvacfirvin
Premium Member
Premium Member
Posts: 49
Joined: Fri Dec 14, 2007 1:43 pm

Post by visvacfirvin »

I think the following command will work

wc -l <filename> | cut -f"1" -d" "

Thanks,
Firvin
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

Thanks for the solution.

I have another problem with 'Execute Command' activity stage.I want to get nth line out of a file (in a loop) and then separate the fields in that line.

Currently I am using a 'Execute Command' activity :

sed -n #StartLoop_Activity_1.$Counter#p</dev/1.txt

It is supposed to give output as :

"abc","def","ghi"

Then I am using an UserVariable activity to separate fields like :

Field(Read_File.$CommandOutput,',',1)
Field(Read_File.$CommandOutput,',',2)
Field(Read_File.$CommandOutput,',',3)

Then I am passing these variables to some other job as parameter.

The problem is that, I am getting empty values (for parameters) in all those fields in UserVariable activity stage.

My dbout is, though the 'sed' command shows the output correctly, but it does a 'print' on stdout, so the individual field values may not get passed to Uservariable activity.

Is that correct? Do I have any other option to read nth line in a loop.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your Field() functions assume "," as the delimiter, but your sed output is more likely to have "\n" as the delimiter. You need to align these, perhaps convert each \n to a comma in the sed script.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

I am trying to use the following in my Start Loop activity 'To' value :

wc -l <filename> | cut -f"1" -d" "

I have start value : 1, Step/Increment : 1

basically to go looping till the last record in the file.

But it gives error saying highest loop value has to be Numeric.

In the DS Sequence, my intention is to process each line in the file, till the last record.

Any better solution.
visvacfirvin
Premium Member
Premium Member
Posts: 49
Joined: Fri Dec 14, 2007 1:43 pm

Post by visvacfirvin »

Looks like its interpreting the outcome of wc -l as string. Try converting the value to integer.

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

Post by ray.wurlod »

What you get back from wc is the result followed by a newline.
When this comes into DataStage, the newline is converted into a field mark.
You need to trim the field mark or extract the field from the returned dynamic array.

Code: Select all

Trim(ECActivity.$CommandOutput,@FM,"T")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
srimitta
Premium Member
Premium Member
Posts: 187
Joined: Sun Apr 04, 2004 7:50 pm

Post by srimitta »

1). awk 'END{ print NR}' <filename>
Execute Command stage will return value 10 in char format.
2). Convert Exec Command stage return value to Integer using

Code: Select all

Oconv(Exec_Command.$CommandOutput,"MCN")
User Variable stage.
Quality is never an accident; it is always the result of high intention, sincere effort, intelligent direction and skillful execution; it represents the wise choice of many alternatives.
By William A.Foster
snt_ds
Premium Member
Premium Member
Posts: 280
Joined: Wed Oct 18, 2006 11:53 am
Location: Pune, India

Post by snt_ds »

Use this command,

wc -l * |awk '{print $1}'

Thanks

mydsworld wrote:I am trying to use the following in my Start Loop activity 'To' value :

wc -l <filename> | cut -f"1" -d" "

I have start value : 1, Step/Increment : 1

basically to go looping till the last record in the file.

But it gives error saying highest loop value has to be Numeric.

In the DS Sequence, my intention is to process each line in the file, till the last record.

Any better solution.
snt_ds
Premium Member
Premium Member
Posts: 280
Joined: Wed Oct 18, 2006 11:53 am
Location: Pune, India

Post by snt_ds »

Use this command,

wc -l * |awk '{print $1}'

Thanks

mydsworld wrote:I am trying to use the following in my Start Loop activity 'To' value :

wc -l <filename> | cut -f"1" -d" "

I have start value : 1, Step/Increment : 1

basically to go looping till the last record in the file.

But it gives error saying highest loop value has to be Numeric.

In the DS Sequence, my intention is to process each line in the file, till the last record.

Any better solution.
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

Thanks to all.

How to convert '\n' to comma in the 'sed' script.

The 'sed' output is like :

"1111","DEFAULT PATH","1"

Then I am trying to get the individual values with UserVariable activity :

Var1 : Field(Read_File.$CommandOutput,',',1)
Var2 : Field(Read_File.$CommandOutput,',',2)
Var3 : Field(Read_File.$CommandOutput,',',3)

but Var1 is coming with "1111" (with a newline at end)

Please advise, how to get Var1 with "1111" or 1111.
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

If anyone has faced the problem described, please help.

Thanks.
Post Reply