bash - comment host file rows containing a string, if not already commented -
i attempting comment several entries in [/etc/hosts] file using sed. have following command works great:
sed -i$(date +%s).bak '/devops/,/devops/s/^/# /' /etc/hosts my problem comes when re-run script containing above line, commented lines new comment. how can add ability skip commented [^#] rows?
thank you, lars
comment lines not commented:
sed -i$(date +%s).bak '/^[^#]*devops/s/^/# /' /etc/hosts
Comments
Post a Comment