1748167 Members
3996 Online
108758 Solutions
New Discussion юеВ

Re: sed question?

 
SOLVED
Go to solution
Allanm
Super Advisor

sed question?



#ssh host1 sed '$d' /root/hosts > /etc/hosts
sed: -e expression #1, char 8: Extra characters after command

How to use sed thru ssh on a remote host?

Thanks,
Allan
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: sed question?

Have you tried quoting the command?

#ssh host1 "sed '$d' /root/hosts > /etc/hosts"
Allanm
Super Advisor

Re: sed question?

Yes tried but didnt work.
James R. Ferguson
Acclaimed Contributor

Re: sed question?

Hi Allan:

# ssh -n host1 'sed "$d" /root/hosts > /etc/hosts'

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor
Solution

Re: sed question?

Hi (again) Allanm:

Sorry, that should be:

# ssh -n host1 'sed "\$d" /root/hosts > /etc/hosts'

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: sed question?

Hi:

Please remember to evaulate the answers you received, here, too:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1335006

Regards!

...JRF...
Allanm
Super Advisor

Re: sed question?

Thanks James,

Question - Can you explain a little bit why \$d is needed for remote hosts ?

Allan.
James R. Ferguson
Acclaimed Contributor

Re: sed question?

Hi Allanm:

> Question - Can you explain a little bit why \$d is needed for remote hosts ?

We escape the dollar-sign so that the shell doesn't attempt to evaluate $d as a variable, but rather leave that for 'sed' to interpret.

You can see this if you compare:

# sed "$d" /root/hosts

...and:

# sed "\$d" /root/hosts

...which is why if we wrote this to run locally, we could do:

# sed '$d' /root/hosts

...with the sinqle quotes so that the shell doesn't try to evaluate the $.

Regards!

...JRF...
Allanm
Super Advisor

Re: sed question?

Exellent, Thanks JRF!