3 ms·
What is the easiest way to make sure a "field, or option" is present in a file. Similar to what ansible's lineinfile does? For example suppose I need to add th
by jaimehrubiks 5y ago
What is the easiest way to make sure a "field, or option" is present in a file. Similar to what ansible's lineinfile does?
For example suppose I need to add this setting to /etc/ssh/sshd_config:
PermitRootLogin yes
One idea that comes to mind is to first delete the line with the line shown in this post, and then add it back:
Regex sed -E '/^#/d' file.txt - delete lines where regex matches
sed -E '/^PermiteRootLogin/d' /etc/ssh/sshd_config ; echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
Is there a more straightforward way with sed?
- pnutjam 5y agohttps://stackoverflow.com/questions/13014055/sed-command-how-to-replace-if-exists-else-just-insert https://stackoverflow.com/questions/13014055/sed-command-how...