sed question? (169 Views)
Reply
Super Advisor
Allanm
Posts: 287
Registered: ‎08-13-2007
Message 1 of 9 (169 Views)
Accepted Solution

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
Honored Contributor
Patrick Wallek
Posts: 13,774
Registered: ‎06-21-2000
Message 2 of 9 (169 Views)

Re: sed question?

Have you tried quoting the command?

#ssh host1 "sed '$d' /root/hosts > /etc/hosts"
Super Advisor
Allanm
Posts: 287
Registered: ‎08-13-2007
Message 3 of 9 (169 Views)

Re: sed question?

Yes tried but didnt work.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 9 (169 Views)

Re: sed question?

Hi Allan:

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

Regards!

...JRF...
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 9 (169 Views)

Re: sed question?

Hi (again) Allanm:

Sorry, that should be:

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

Regards!

...JRF...
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 6 of 9 (169 Views)

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
Allanm
Posts: 287
Registered: ‎08-13-2007
Message 7 of 9 (169 Views)

Re: sed question?

Thanks James,

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

Allan.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 8 of 9 (169 Views)

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
Allanm
Posts: 287
Registered: ‎08-13-2007
Message 9 of 9 (169 Views)

Re: sed question?

Exellent, Thanks JRF!
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.