sed Help

Hi,

I want to replace

[[ $SSH_TTY != "" ]]  with #[[ $SSH_TTY != "" ]] 

their is a extra # in second one and vice versa.

I tried - some combination...I am not getting the exact result...please help

Hi guy,
mean this?

echo '[[ $SSH_TTY != "" ]]'|sed 's/\[\[ $SSH_TTY != "" ]]/#&/'

Thanks..I tried this and it echoed the desired result

echo '[[ $SSH_TTY != "" ]]'|sed 's/\[\[ $SSH_TTY != "" ]]/#&/'  

How make it write on the file ?

ex: /home/myfile

u r welcome~

Is this [[ $SSH_TTY != "" ]] in the current /home/myfile now, and you want to replace it and write back to this file?

If so, just try this:

mv /home/myfile /home/myfile.bak
sed 's/\[\[ $SSH_TTY != "" ]]/#&/' /home/myfile.bak > /home/myfile

and if your OS is linux and doesn't need a backup, with option -i in gnu sed, can just do this:

mv /home/myfile /home/myfile.bak
sed -i 's/\[\[ $SSH_TTY != "" ]]/#&/' /home/myfile

Thanks buddy..This works for me... Have a good day ahead :slight_smile:

I will check the reverse part.