Problem Using Sed via Routine Activity

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
richieRich
Premium Member
Premium Member
Posts: 27
Joined: Tue Jan 05, 2010 12:04 am

Problem Using Sed via Routine Activity

Post by richieRich »

Hi All,

I am having a strange problem whilst trying to use Sed via a Routine Activity Stage in my sequence job. I am doing a global replace of multiple patterns. Sed is working to replace text but as soon as I start to try and replace numbers it is getting totally confused. I assume this is something to do with the translation of my numbers from DataStage to unix because when I run a number replace directly in my unix prompt i don't have any problems....

My source file has one word in it...
BUSINESS_DATE_YYYYMMDD

Here is an example of what happens...

Example 1. Working
------------------------------
Routine Activity Code

"sed -e ":CHAR(34):" s/\&apos;/\'/g;" :
"s/\</\</g;" :
"s/\>/\>/g;" :
"s/\BUSINESS_DATE_YYYYMMDD/\": "Test" : "/g" :
CHAR(34): " " :
<<SourceFile>> : ">> /tmp/out.txt && " :
"rm ": <<SourceFile>> && ":
"mv /tmp/out.txt": " " : <<SourceFile>>

Resultant File
Test

Example 2. Working
------------------------------
Routine Activity Code

"sed -e ":CHAR(34):" s/\&apos;/\'/g;" :
"s/\</\</g;" :
"s/\>/\>/g;" :
"s/\BUSINESS_DATE_YYYYMMDD/\": "#BUSINESS_DATE#" : "/g" :
CHAR(34): " " :
<<SourceFile>> : ">> /tmp/out.txt && " :
"rm ": <<SourceFile>> && ":
"mv /tmp/out.txt": " " : <<SourceFile>>

Resultant File
#BUSINESS_DATE#

Example 3. Not Working
------------------------------
Routine Activity Code

"sed -e ":CHAR(34):" s/\&apos;/\'/g;" :
"s/\</\</g;" :
"s/\>/\>/g;" :
"s/\BUSINESS_DATE_YYYYMMDD/\": "20100908" : "/g" :
CHAR(34): " " :
<<SourceFile>> : ">> /tmp/out.txt && " :
"rm ": <<SourceFile>> && ":
"mv /tmp/out.txt": " " : <<SourceFile>>

Resultant File
BUSINESS_DATE_YYYYMMDD


Yet when I try and do the same thing on the command line it works...
sed 's/BUSINESS_DATE_YYYYMMDD/20100908/g' <<SourceFile>>

Resultant File
20100908


Has anyone got any ideas?

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

Post by ray.wurlod »

You should not be using a Routine activity; you should be using an Execute Command activity. sed is not a routine, it is a command.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
richieRich
Premium Member
Premium Member
Posts: 27
Joined: Tue Jan 05, 2010 12:04 am

Post by richieRich »

Thanks Ray. That way the hint I needed. I've got it to work now. The only thing I'm confused about is how to run a command straight after my sed.

In my routine activity I could do a sed, redirect the output to /tmp then do a && and then write another command to overwrite my original file with the redirected output from /tmp


eg. sed command /dir/sourcefile > /tmp/file && mv /tmp/file /dir/sourcefile

Is there a way I can run a command straight after sed to overwrite my original file using the execute command activity. Or do I need another execute command stage?

Thanks
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Use these commands in single Execute command activity

Code: Select all

sed command /dir/sourcefile > /tmp/file && mv /tmp/file /dir/sourcefile 
Or

Code: Select all

sed command /dir/sourcefile > /tmp/file;mv /tmp/file /dir/sourcefile 
You are the creator of your destiny - Swami Vivekananda
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

In other words, just like you thought. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
richieRich
Premium Member
Premium Member
Posts: 27
Joined: Tue Jan 05, 2010 12:04 am

Post by richieRich »

Yep Thanks guys....

Command=sed -e
Parameters=
"s/\&apos;/\'/g;s/\</\</g;s/\>/\>/g;s/DATE_YYYYMMDD/#DATE#/g" MyFile.txt > /tmp/out.txt && rm MyFile.txt && mv /tmp/out.txt MyFile.txt

It was just confusing seeing the Command as Sed -e. I wasn't sure whether that Execute Command activity was limited it to sed.
Post Reply