I am looking for changing a file content which is repeated twice with that replacement I want to add extra line to second content in the same file
Example file
User YOURNAME
IdentityFile ~/.ssh/YOURKEY
.
.
.
User YOURNAME
Installing
Installing
Example Output after running script
User adminuser
IdentityFile ~/.ssh/id_rsa
.
.
.
User adminuser
IdentityFile ~/.ssh/id_rsa
Installing
Installing
I am able to change the user
and YOURKEY
with the below sed
command
`sed- i s/"YOURNAME/adminuser"/g /root/.ssh/config`
`sed -i 's/YOURKEY/id_rsa/g' ff1`
But I'm unable to insert IdentityFile ~/.ssh/id_rsa
in the next line.
edited
additional info ****User adminuser
is having space at the beginning of the line. These files are getting synced on daily bases, So cant remove IdentityFile
line. After sync it will get replaced
Final edit which works as required
perl -i -ne 'next if /IdentityFile/;
s#YOURNAME#adminuser\n IdentityFile ~/.ssh/id_rsa#;
print' filename
****User adminuser
is having space at the beaning of the line