Code uncomment a line in a text file which matches a word:
Code:
sed -i "/<My-word>/s/^#//g" file-name
We are using sed, this works in most Linux/Unix distributions (including Linux docker containers)

Explanation:
  • -i edit files in place
  • /<My-word>/ the pattern or work you wanted to match
  • /^#/ Look for lines starting with a hash, "#"
  • // replace with empty character
  • file-name the name of your file this operation needs to be done

Demo to uncomment local hosting of devopsrun.com


Code:
cat /etc/hosts
#127.0.0.1      www.devopsrun.com
Let us uncomment it,
Code:
sed -i "/devopsrun/s/^#//g" /etc/hosts
Verifying:
Code:
cat /etc/hosts
127.0.0.1       www.devopsrun.com