Article 4ZEDG How to specify optional character with sed

How to specify optional character with sed

by
jodumont
from LinuxQuestions.org on (#4ZEDG)
Hi;

I saw this before but unable to find it via google

basically I want to put in one line these sed
sed -i 's|^Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|#Port .*|Port 55555|g' > /etc/ssh/sshd_config

I tried
sed -i 's|^[,#]Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|[^,#]Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|[^\|#]Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|^[\|#]Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|^[,#]Port .*|Port 55555|g' > /etc/ssh/sshd_config

sed -i 's|^(,#)Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|(^,#)Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|(^\|#)Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|^(\|#)Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|^(,#)Port .*|Port 55555|g' > /etc/ssh/sshd_config

sed -i 's|^{,#}Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|{^,#}Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|{^\|#}Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|^{\|#}Port .*|Port 55555|g' > /etc/ssh/sshd_config
sed -i 's|^{,#}Port .*|Port 55555|g' > /etc/ssh/sshd_config

and probably more but never succeedlatest?d=yIl2AUoC8zA latest?i=j6SjT2P4n90:m41d-FpRobE:F7zBnMy latest?i=j6SjT2P4n90:m41d-FpRobE:V_sGLiP latest?d=qj6IDK7rITs latest?i=j6SjT2P4n90:m41d-FpRobE:gIN9vFwj6SjT2P4n90
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments