LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2009, 04:40 PM   #1
rma88
LQ Newbie
 
Registered: May 2007
Posts: 12

Rep: Reputation: 0
help - how do i run a multi-line sed command in perl?


hey everyone,

I'm writing a little perl script that is editing all my .php files and inserting a google-analytics piece of code before the </body> tag.

the sed command works just find from command line, and is such :

Code:
sed '/<\/body>/ i\
<script type="text/javascript"> \
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); \
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); \
</script> \
<script type="text/javascript"> \
try { \
var pageTracker = _gat._getTracker("UA-10500631-2"); \
pageTracker._trackPageview \
} catch(err) {}</script>
' MyPage.php
this works fine, however, how am I supposed to execute this in a perl script? I can't put it in a double quoted string, or a single quoted string, because the command contains both double and single quotes. Also, it spans multiple lines...

I have tried putting it in backticks over multiple lines just as is, that doesn't work. i've take out all the spaces and the '\' and made it a single, really long one line command and it doesn't work.

I'm at a loss, if anyone can show me what to do it would be really appreciated... this is the last little bit of the script, so any help is greatly appreciated!
 
Old 10-09-2009, 06:53 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you don't have to execute that piece of sed code in Perl. You can do what that sed does with Perl as well.. either s/// or find the index where </body> lies and add text after it.

Last edited by ghostdog74; 10-09-2009 at 06:56 PM.
 
Old 10-09-2009, 07:11 PM   #3
rma88
LQ Newbie
 
Registered: May 2007
Posts: 12

Original Poster
Rep: Reputation: 0
ah, very cool.

i'll go look at the s///.

ya i was going to avoid parsing the script in perl and adding the text because i already had a quick little sed command.

thanks, i'll check out s///.
much appreciated.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] move a line with either sed/awk/perl script don_wombat_73 Linux - Newbie 9 07-07-2009 01:06 PM
Multi-line find/replace with GnuWin32 Sed Question EdrickV Programming 4 04-26-2009 01:32 PM
sed multi-line search/replace woes djmm Programming 8 03-17-2009 05:25 AM
Perl Multi-Line Search & Replace... Can I?... donv2 Linux - Newbie 2 01-30-2007 09:59 PM
Multi line perl pie dlublink Programming 4 07-06-2006 10:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration