Page 1 of 1

Command execute activity

Posted: Mon Jul 28, 2008 12:38 pm
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 .

Posted: Mon Jul 28, 2008 12:58 pm
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.

Posted: Mon Jul 28, 2008 12:59 pm
by visvacfirvin
I think the following command will work

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

Thanks,
Firvin

Posted: Mon Jul 28, 2008 2:03 pm
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.

Posted: Mon Jul 28, 2008 4:16 pm
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.

Posted: Mon Jul 28, 2008 7:56 pm
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.

Posted: Mon Jul 28, 2008 8:41 pm
by visvacfirvin
Looks like its interpreting the outcome of wc -l as string. Try converting the value to integer.

Firvin.

Posted: Mon Jul 28, 2008 10:43 pm
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")

Posted: Tue Jul 29, 2008 7:10 am
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.

Posted: Tue Jul 29, 2008 7:53 am
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.

Posted: Tue Jul 29, 2008 7:55 am
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.

Posted: Tue Jul 29, 2008 1:05 pm
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.

Posted: Wed Jul 30, 2008 9:12 pm
by mydsworld
If anyone has faced the problem described, please help.

Thanks.