This is what I was hoping would work utilizing sed, but no dice so far:
sed '/^command=/ /\/opt\/home\/user/!s@/home/user/@/opt/home/user/@' authorized_keys
Note that the @ is just a funny delimiter I chose for the substitution to more easily view the slashes.
Basically what I want that regex to do is: "On any line in the file starting with the string: command= then if the string: /opt/home/user does not exist, then replace /opt/user with /opt/home/user"
I know I could theoretically do this with if statements, greps, and then sed, but that seems non elegant to me. I am pretty certain sed can do this itself in a one liner regex, but any combination I've tried seems to give me all sorts of syntax errors. Oddly enough, those regex statements used individually don't give any syntax errors when combined with the substitution, only when I try to combine them do I have issues.
Anyone have a more elegant way to do this with sed? Or was I right in assuming that greps, and if statements before the sed are the best way to do this.