Showing results for 
Search instead for 
Do you mean 

sed question?

SOLVED
Go to Solution
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
1 ACCEPTED SOLUTION
Acclaimed Contributor Acclaimed Contributor

Re: sed question?

Hi (again) Allanm:

Sorry, that should be:

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

Regards!

...JRF...
8 REPLIES
Honored Contributor Honored Contributor

Re: sed question?

Have you tried quoting the command?

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

Re: sed question?

Yes tried but didnt work.
Acclaimed Contributor Acclaimed Contributor

Re: sed question?

Hi Allan:

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

Regards!

...JRF...
Acclaimed Contributor Acclaimed Contributor

Re: sed question?

Hi (again) Allanm:

Sorry, that should be:

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

Regards!

...JRF...
Acclaimed Contributor 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...
Super Advisor

Re: sed question?

Thanks James,

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

Allan.
Acclaimed Contributor 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...
Super Advisor

Re: sed question?

Exellent, Thanks JRF!