I'm just now getting around to learning sed and I am trying to do what I thought would be a very basic sed command, but it has turned into one of the most confusing things I've ever had to do in Linux
I don't know why this is so hard for me, but all I need to do is find
the first line that contains $find and replace the entire line with $replace. Oh, and I forgot to mention I'm trying to do this from a perl script. After many hours of banging my head on the keyboard, I got it to work (assuming there is only one occurence of $find). The problem is that there is not only one occurence. Here is a snippet of the perl code calling sed, I never thought I would have to write code that had more symbols then letters
Code:
$find="browser.startup.homepage";
$replace="user_pref'\('\\\"'browser.startup.homepage'\\\"', ''\\\"'$homepg'\\\"''\)''\;'";
$cmd="sed -i -e '/'$find'/a'$replace'' -e '/'$find'/d' /etc/wcprofile/prefs.js";
system("$cmd");
For anyone that noticed, yes I'm trying to change the homepage in the mozilla prefs. Please don't respond with "why don't you just change the settings in the browser".
OK, now I've read everything I could find about sed and it seems there is a lot of conflicting information out there. This little blurb in the man page seems the most promising:
Quote:
q - Immediately quit the sed script without processing any more input, except that if auto-print is not disabled the current pattern space will be printed.
|
Unfortunately, I can't for the life of me figure out how to use it correctly. I still don't really get how the sed "commands" work, and how to use multiple commands at once (IE. delete then quit) I've tried experimenting with a lot of diffrent syntax, but no luck.
Maybe there is an easier way to change the homepage in prefs.js from a perl script?
Code:
user_pref("browser.startup.homepage", "http://www.google.com");
user_pref("browser.startup.homepage_override.mstone", "rv:1.8.0.4");
The second line is the one giving me all the headache. This needs to remain unchanged.
Could any of you gurus out there help a tortured soul?
thanks!
...drkstr