Command execute activity
Moderators: chulett, rschirm, roy
Command execute activity
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 .
the output I am getting is :
10 <filename>
However, I expect :
10
i have used :
command : wc
Parameters : -l <filename>
Is it correct .
-
- Premium Member
- Posts: 49
- Joined: Fri Dec 14, 2007 1:43 pm
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.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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.
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.
-
- Premium Member
- Posts: 49
- Joined: Fri Dec 14, 2007 1:43 pm
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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 User Variable stage.
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")
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
By William A.Foster
Use this command,
wc -l * |awk '{print $1}'
Thanks
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.
Use this command,
wc -l * |awk '{print $1}'
Thanks
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.
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.
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.