awk in execute command activity

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
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

awk in execute command activity

Post by reachmexyz »

Hi.
In my job, i have a rejection file. If the rejection has any records i have to send a notification.
Lets say i am storing the rejections in a file called "rejs".
So what i have done is
linked the job activity with command activity--> notification
In command activity
command: wc -l
params: rejs

under triggers:
left(command activity. job output, @FM,1)>0

so when the wc -l was executed, output is like
0 rejs
if i use awk '{print $1}' i will get the output as 0.
Where can i add this awk command in execute command activity.
do i need to add one more exec command activity and put
awk '{print $1}' commandactivity.job output.
or can i do this in the already exsiting command activity.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Pipe the output of wc -l rejs to your awk command.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

Post by reachmexyz »

DSguru2B wrote:Pipe the output of wc -l rejs to your awk command.
So do i need to use another command activity to execute this awk command.
In a single exec command activity, cant i use both wc -l command and awk command
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You should be able to. Thats why my advice above.
Basically

Code: Select all

wc -l rejs | awk '{print $1}' 
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

Post by reachmexyz »

DSguru2B wrote:You should be able to. Thats why my advice above.
Basically

Code: Select all

wc -l rejs | awk '{print $1}' 
Thanks
I got it
Previously i never thought i can give the command along with file name
in the command box and leave the parameters box empty.
I was using wc -l in command box and file name in parameters box of exec command activity.
Now i have used "wc -l filename |awk '{print $1}'" in the command box.
Thanks for the responsse
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

Post by reachmexyz »

DSguru2B wrote:You should be able to. Thats why my advice above.
Basically

Code: Select all

wc -l rejs | awk '{print $1}' 
Well,
I got another issue.
file name actually used contains parameters.
File name wil be like
#path#/rejs.
So when i put this in the command activity, respose is "command activity cannot contain parametes"
If i put the file name in parameters box, i am unable to awk it.
How can i do this?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Split it up so that a part without parameters is in the Command box and the rest (the bit with parameters) is in the Parameter box. All the stage does is stick the two pieces together and then run it.

The only 'trick' to know is when the very first bit (typically a path to a script) is a parameter, then what you do is put "ksh" or "sh" in the command box and everything else in the parameter box.
-craig

"You can never have too many knives" -- Logan Nine Fingers
reachmexyz
Premium Member
Premium Member
Posts: 296
Joined: Sun Nov 16, 2008 7:41 pm

Post by reachmexyz »

chulett wrote:Split it up so that a part without parameters is in the Command box and the rest (the bit with parameters) is in the Parameter box. All the stage does is stick the two pieces together and then run it.

The only 'trick' to know is when the very first bit (typically a path to a script) is a parameter, then what you do is put "ksh" or "sh" in the command box and everything else in the parameter box.


Problem solved.
All the stage does is stick the two pieces together and then run it.

when the above sentence is true, then why do we need two boxes(command , parameters) in the exec command activity.
We can only have one box where we put the whole command along with parameters also can be combined with pipes.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Because that's how whoever write the Execute Command activity wrote it.

You may as well ask why we need to have the SELECT clause first in SQL, even though the FROM clause is parsed first.
Why can't we write

Code: Select all

FROM table SELECT columns WHERE condition;
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
throbinson
Charter Member
Charter Member
Posts: 299
Joined: Wed Nov 13, 2002 5:38 pm
Location: USA

Post by throbinson »

Actually I think a better question is why awk at all? Why two commands where one would do?

Code: Select all

test -s #FileName#
man test
-s FileName
Returns a True exit value if the specified FileName exists and has a size greater than 0.
Post Reply