Perl pi replace all question...

what i'm trying to do here.....

I want to use a sed or perl pi find command for index.html because there is 40,000 plus index files.

i want to replace this

Code:
<script type="text/javascript"><!--
google_ad_client = "pub-6546456544";
/* 336x280, created 7/23/10 */
google_ad_slot = "4565464565";
google_ad_width = 336;

with...

Code:
<font size="-1">Sponsored Listings</font>
<script type="text/javascript"><!--
google_ad_client = "pub-6565466656";
/* 336x280, created 7/23/10 */
google_ad_slot = "45645654645";
google_ad_width = 336;
 
just read it going to try it now.

i notice on all yopur code you end it like this

Code:
;#<font size="-1">Sponsored Listings</font>
&#gI'

how come you don't display the rest of the string that needs to be replaced? OR does this
code make it not repetitive in the command? will it print the rest of it out?
 
just tired this exact command and no go.


Code:
find . -name '*index.html' -print0 | xargs -0 sed -I -e 's#<script type="text/javascript"><!--google_ad_client = "pub-4545545545655";/\* 
336x280, created 1/23/10 \*/google_ad_slot = "5464565";google_ad_width = 336;#<font size="-1">Sponsored Listings</font>
&#gI'
 
Are there newlines somewhere in string we are searching?
perhaps you can upload some 2 files for me to play with [if that's not a commercial secret]
 
the code looks exactly like this in each index.html page in each subdomain. google wants me to place "Sponsored links at the top of each google adsense ad in the middle of all my pages.


Code:
[align=center]<p>



<script type="text/javascript"><!--
google_ad_client = "pub-999999999999999";
/* 336x280, created 1/23/10 */
google_ad_slot = "55555555555";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
 
I have Idea how to fix this using VIM :D. lol
But it's too ugly to explain, would take a week, and this is not the way to do things

Right now I have no ideas that I can show, how to fix your problem, maybe something with awk
 
This thread is turning into a chat that will probably not interest anyone else by now. I suggest you resort to using Private Messaging or other means of direct contact.
 
fix.sed
Code:
1h
1!H
${
g
s#[color="Red"]<script type="text/javascript"><!--\ngoogle_ad_client = "pub-999999999999999";\n/\* 336x280, cre[B]a[/B]
ted 1/23/10 \*/\ngoogle_ad_slot = "55555555555";\ngoogle_ad_width = 336;\ngoogle_ad_height = 280;\[B]n[/B]
//-->\n</script>\n<script type="text/javascript"\nsrc="http://pagead2\.googlesyndication\.com/page[B]a[/B]
d/show_ads\.js">\n</script>[/color]#[color="SeaGreen"]<font size="-1">Sponsored Listings</font>
&[/color]#gI
p
}
I split regex in middle of words.... character after which I split it, I marked bold...
so when you joint lines, make sure you don't have space between :)

testfile
Code:
aaaaaaaaaaaaaaaaaaaaaaaaaaa
[align=center]<p>



<script type="text/javascript"><!--
google_ad_client = "pub-999999999999999";
/* 336x280, created 1/23/10 */
google_ad_slot = "55555555555";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

$ sed -n -f fix.sed testfile > fixedfile

fixedfile
Code:
aaaaaaaaaaaaaaaaaaaaaaaaaaa
[align=center]<p>



<font size="-1">Sponsored Listings</font>
<script type="text/javascript"><!--
google_ad_client = "pub-999999999999999";
/* 336x280, created 1/23/10 */
google_ad_slot = "55555555555";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

so you need to run $ find . -name '*index.html' -print0 | xargs -0 sed -I bak -n -f fix.sed


You love me, don't you? :D

P.S.
If some files are written on windows you will have to fix \n with \r\n or something like that
 
You'd have made things easier for yourself by ignoring the bulk of the data (most of it is just printed verbatim).

A simple perl oneliner like this would be sufficient

Code:
perl -ne 's/<script type="text\/javascript"><\!--/<font size="-1">Sponsored Listings<\/font>
$&/; print'
 
jalla said:
You'd have made things easier for yourself by ignoring the bulk of the data (most of it is just printed verbatim).

A simple perl oneliner like this would be sufficient

Code:
perl -ne 's/<script type="text\/javascript"><\!--/<font size="-1">Sponsored Listings<\/font>
$&/; print'

There can be many other embedded javascripts
 
Of course, my point was the simple regexp substitution.
You have to put this into a toolchain like find .. | xargs perl -ine ...
 
Back
Top