Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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!