Question

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

No correct solution

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top