Languages and Scripting

Re: find and replace xml tag value in file extended

 
SOLVED
Go to solution
GOPI KRSNA
Occasional Contributor

find and replace xml tag value in file extended

Hi All,

I am just extending the thread started by diwakar with my query.
James R. Ferguson have replied that
# perl -pe 's{(http://)(.+)()}{$1www.dummy.com$3}g' file

By using this perl code we can find and replace partciular tab value in xml file. This is working fine for me also. I want to add some more check like it should also replace url which are staring with https/HTTP/HTTPS(Case sensitive..) so can any one help me how to add OR condtion in this?

Thanks
Gopi
8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: find and replace xml tag value in file extended

>I am just extending the thread started by diwakar with my query.

It would have been helpful to provide the URL:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1351538

With sed, you just provide two "-e 's///g'".

Hakki Aydin Ucar
Honored Contributor

Re: find and replace xml tag value in file extended

I prefer to use HP UX command sed:

cat your_file | sed 's/HTT/HTTPS/'
GOPI KRSNA
Occasional Contributor

Re: find and replace xml tag value in file extended

Hi,

I will prefer to update perl code , acuatlly i have many xmls that has one tab called which may contains
Hope James R. can help me in this regard if he is able to see my case.

Thanks
Fredrik.eriksson
Valued Contributor

Re: find and replace xml tag value in file extended

You can always do "OR" commands :)

perl -pe "s/((http|https):\/\/)(?:[^<]+)(<\/Attachmen
tURLprefix>)/$1www.dummy.com$3/g" test.txt

(http|https) can be extended just by adding pipes and the keyword.
If you by some reason would want to match the old url as well you can remove ?: in (?:[^<]+) and $3 will become that address ($4 will be

Output looks like this.
V0001> perl -pe "s/((http|https):\/\/)(?:[^<]+)(<\/Attachmen
tURLprefix>)/$1www.dummy.com$3/g" test.txt
http://www.dummy.com
https://www.dummy.com

Best regards
Fredrik Eriksson
GOPI KRSNA
Occasional Contributor

Re: find and replace xml tag value in file extended

Hi Fedric,

It is giving me error like :

sh: 1: Parameter not set.


Thanks
James R. Ferguson
Acclaimed Contributor
Solution

Re: find and replace xml tag value in file extended

Hi Gopi:

> sh: 1: Parameter not set.

Change the double quotes that enclose the command line script to single ones when you run a Perl script from a Unix shell:

# perl -e '...'

...instead of:

# perl -e "..."

...which is what silly Windows wants.

Regards!

...JRF...
GOPI KRSNA
Occasional Contributor

Re: find and replace xml tag value in file extended

Hi James R. , Fedric

Many thanks it is resolved now.

Thanks
Fredrik.eriksson
Valued Contributor

Re: find and replace xml tag value in file extended

James, was actually running it under OpenVMS :P

But yeah, single quotes :)

Best regards
Fredrik Eriksson