Problem Using Sed via Routine Activity
Posted: Wed Sep 22, 2010 12:49 am
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/\'/\'/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/\'/\'/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/\'/\'/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
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/\'/\'/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/\'/\'/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/\'/\'/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