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
Problem Using Sed via Routine Activity
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 27
- Joined: Tue Jan 05, 2010 12:04 am
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 27
- Joined: Tue Jan 05, 2010 12:04 am
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
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
Use these commands in single Execute command activity
Or
Code: Select all
sed command /dir/sourcefile > /tmp/file && mv /tmp/file /dir/sourcefile
Code: Select all
sed command /dir/sourcefile > /tmp/file;mv /tmp/file /dir/sourcefile
You are the creator of your destiny - Swami Vivekananda
-
- Premium Member
- Posts: 27
- Joined: Tue Jan 05, 2010 12:04 am
Yep Thanks guys....
Command=sed -e
Parameters=
"s/\'/\'/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.
Command=sed -e
Parameters=
"s/\'/\'/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.