Results 1 to 7 of 7
what do you do when sed works, but only half the time?
i am writing a script that will replace some text in some config files but i am noticing ...
- 10-23-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 15
sed errors, is there another way?
what do you do when sed works, but only half the time?
i am writing a script that will replace some text in some config files but i am noticing the sed sucks! it only works about half the time and the other half i get obscure errors. i'm tired of trying to track down the problem with sed.
is there another way of replacing a specific string in a config file without using the sed command?
- 10-23-2007 #2
Sure. Learn Perl. It's at least as bug-free as sed is.
Learn Perl, and you win. Show us with a concrete example how sed is misbehaving, and we'll show you how you're wrong, and everybody wins.
Your choice.
- 10-24-2007 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
show your sed code, as well as the input file.
a variety of tools such as Python, awk, even the bash shell has in built string replacement, lastly but not least, Perl.
in awk,
however, it also very depends on how your input file looks like.Code:awk '{ gsub("old,"new")}{print}' file
- 10-24-2007 #4Just Joined!
- Join Date
- Sep 2007
- Posts
- 15
it is easy to get frustrated when a deadline approaches and you are stuck in the mud.
i may try and use awk, but i really need to learn perl too.
i am trying to use sed in a script to replace some configuration settings in four different conf files.
it seems to work, sort of. The four files are /etc/network/interfaces, /etc/postfix/main.cf, /etc/MailScanner/spam.assassin.prefs.conf, and /etc/MailScanner/MailScanner.conf
it is the MailScanner.conf file that has been giving me trouble.
to make matters worse, i'm doing this all within a virtual machine. the errors don't appear in the original version but show up after i copy the machine. from the original machine my code seems to do exactly what i want.
here is the error that I get when i run it in the copied version of the virtual machine.
sed: -e expression #1, char 24: unterminated `s' command
sed: -e expression #1, char 28: unterminated `s' command
of course when i cat the file that was supposed to be changed it is empty.
my code looks thus...
cat /etc/MailScanner/MailScanner.conf | sed s/ORGNAME/$OName/ > MailScanner.1.conf.tmp
cp MailScanner.1.conf.tmp /etc/MailScanner/MailScanner.conf
rm MailScanner.1.conf.tmp
cat /etc/MailScanner/MailScanner.conf | sed s/ORGLONGNAME/$LName/ > MailScanner.2.conf.tmp
cp MailScanner.2.conf.tmp /etc/MailScanner/MailScanner.conf
rm MailScanner.2.conf.tmp
cat /etc/MailScanner/MailScanner.conf | sed s/SITENAME/$OSite/ > MailScanner.3.conf.tmp
cp MailScanner.3.conf.tmp /etc/MailScanner/MailScanner.conf
rm MailScanner.3.conf.tmp
i've tried doing this using only one temp file as i did with the other files but that did not seem to work. this code actually does work, sort of...
i sure do appreciate any help you can give...
- 10-24-2007 #5Just Joined!
- Join Date
- Sep 2007
- Posts
- 15
oh you know what... i just noticed something. only in my MailScanner.conf file do i ask for an input that could have a space in it. when the ORGLONGNAME is queried the response may contain spaces, such as foo bar llc. the spaces may be my whole problem.
when i have tested the script i just entered in a string of text with out spaces in order to save time. but after i copy the machine i have attempted to put in genuine values that contain a space or two.
do you think i'm on the right track here?
more importantly, is there a way to deal with this?
- 10-24-2007 #6Hope this helps.Code:
sed s/ORGLONGNAME/$LName/ # bad sed "s/ORGLONGNAME/$LName/" # good
- 10-25-2007 #7Just Joined!
- Join Date
- Sep 2007
- Posts
- 15


Reply With Quote
