Operating System - HP-UX
1753902 Members
9932 Online
108810 Solutions
New Discussion юеВ

Problem with SED in shell script

 
Nagendar
Advisor

Problem with SED in shell script

Hi friends,

I have a strange problem with sed in shell scripts on HP-UX 11.0.

The scripts is like this:
sed -e "s,dummyPort,$PORT,g" < /tmp/new-httpd1.conf >/tmp/new-httpd2.conf

sed -e "s,dummysslPort,$SSL_PORT,g" < /tmp/new-httpd2.conf >/tmp/new-httpd.conf

In the above two sed functions, first sed works fine. Second one gives the following error:
"sed: Function s,dummysslPort,443 cannot be parsed"

I even tried the following:

sed -e "s/a/b" -e "s/b/c" < file1 >file2. This also gives the same error.

I even replaced -e with -n and tried. Still does not work.

Any ideas? Please help.

Thanks,
Nagendar
8 REPLIES 8
Chakravarthi
Trusted Contributor

Re: Problem with SED in shell script

I had a similar problem I changed the last sed command to:

's/$/
'

and the problem went away. I have no idea if that is a reasonable way
to fix it, though.


--chakri
Nagendar
Advisor

Re: Problem with SED in shell script

Hi,

You mean to say replace double quotes (") with with single quotes (') ?

Yes, that works fine. But the problem is that takes the literal values. I mean you can't use a variable in that case. That is another side problem of using single quotes.

Looking forward for more solutions.
Regards,
Nagendar
Jean-Louis Phelix
Honored Contributor

Re: Problem with SED in shell script

hi,

Perhaps problems are not the same ...

In the first case, what is the content of $SSL_PORT ? If it contains a ',' it could generate errors due to string evaluation before execution. Try with another separator like / or ; ...

In your second sed problem, just add a final / and it will work (you must always have a third time the fiel separator.

Regards.
It works for me (┬й Bill McNAMARA ...)
Nagendar
Advisor

Re: Problem with SED in shell script

Hi,

The port does not contain the ",".

Regarding the second suggetion, I have put the third file seperator too in the sed. It does not solve the problem :(

Regards
Nagendar
Advisor

Re: Problem with SED in shell script

Hi, the value of one of params was messed up. Hence the unusual behaviour. Thanks for the replies.

Justo Exposito
Esteemed Contributor

Re: Problem with SED in shell script

Hi Nagendar,

Try this:

sed -e 's/dummysslPort/'$SSL_PORT'/g' < /tmp/new-httpd2.conf >/tmp/new-httpd.conf

Regards,

Justo.
Help is a Beatiful word
Nagendar
Advisor

Re: Problem with SED in shell script

Hi Justo,

Thanks for the suggetion. My actual problem was with the value of SSL_PORT. There was some messup. Thats been resolved. Thanks anyway.

I am closing the message now!

Regards,
Nagendar

KapilRaj
Honored Contributor

Re: Problem with SED in shell script

I have faced many probs with sed it looks like this is the problem

do


cat /tmp/new-httpd2.conf |sed -e "s;dummysslPort;$SSL_PORT;g" >>/tmp/new-httpd.conf


It will work please give a try

Cheers ............


kaps
Nothing is impossible