1

i want to edit file at remote server using solaris

the original file at the remote server that i want to edit is :

11111
22222
33333
44444
55555
66666
77777

and i want to remove the 5th line "55555" and replace it by "00000"

i try this

ssh user@host 'cat ~/path_of_original_file.txt '| sed 's/55555/00000/g' ;

the result appears successfully and the line replaced as i want , but when i open the file at the remote server nothing change !!!!!

mondo32
  • 33
  • 7

1 Answers1

1

There are two things wrong with your attempt:

  1. You pipe the cated output to sed, so you are only changing stdout.

  2. The right-hand-side of the pipe is run locally, not on the remote server since it is outside of your quoted string.

What you probably want is

ssh user@host 'sed -i "s/55555/00000/g" ~/path_of_original_file.txt'

where -i means in-place (see man sed).

Also note that /g will change all occurrances of 55555, not just the first/the one on line 5.

Since you are on Solaris and your sed probably doesn't have -i you need to use a temporary file (see also e.g. here).

Community
  • 1
  • 1
Adrian Frühwirth
  • 39,348
  • 9
  • 57
  • 69
  • thank you very much ,,,,, ^_^ i am new in unix so i still make lots of mistakes ,, i will try and tell you what happen – mondo32 Mar 04 '14 at 10:00