Saturday, May 5, 2012

BEWARE of asterisk!

Some sharing. 

I was about to replace certain string in a specific file in all directories in a AIX machine. We have a Perl script file to perform this action. All this while it has been running fine but not today.

After some troubleshooting i quickly discovered it is due to: the string that we are going to replace contains an asterisk(*) which causes the whole script not working properly.

Very shortly my colleague found a solution, which is to 'escape' the asterisk(*) symbol by putting a backslash(\) symbol right before the asterisk(*) symbol so that when the script is running it will escape the *

Before (this will give error)
perl -p -i -e 's/12345*9/abcde/g' `find ./ -name somefile

After (this will solve the problem)
perl -p -i -e 's/12345\*9/abcde/g' `find ./ -name somefile

No comments:

Post a Comment