Operating System - HP-UX
1833889 Members
2011 Online
110063 Solutions
New Discussion

running sed inside script file

 
Bajaj
New Member

running sed inside script file

i am substituting text in some xml file using sed, on shell directly its working fine, but when i do it using script file, it says, the function cant be parsed, i think the problem is due to xml file special characters, plz help
5 REPLIES 5
RAC_1
Honored Contributor

Re: running sed inside script file

Try escaping it. comething like this.-"\?\"
There is no substitute to HARDWORK
Frank de Vries
Respected Contributor

Re: running sed inside script file

Inside shell vi mode
try

:1,$s!!!g

So from line 1 to end ($)
using not backspaces but exlaimation marks !
g means global, throughout the whole script.
Escape U do undo if unexpected result.

This should normally solve most quoting problems.

Otherwise give the exact text you want to change inside the script.

Look before you leap
Peter Nikitka
Honored Contributor

Re: running sed inside script file

Hi,

without really encrypting the script fragment you supplied, I suggest to try (its a single line!):

sed 's,,\1,' in.xml >out.xml

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Peter Nikitka
Honored Contributor

Re: running sed inside script file

Sorry,

there is a copy/paste error inside - use:

sed 's,,\1,' in.xml >out.xml

to get the xml tags you requested.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Frank de Vries
Respected Contributor

Re: running sed inside script file

A subtle difference, just to be consistent
with what I stated earlier you can do:

To do it from unix prompt outside your script:
sed -e 's!!\1!' < test.sed

Where test.sed contains:


after it looks like this:
file

From within the script with vi mode :
1,$s!!\1!g

exactly the same result :)

Good luck
Look before you leap