Monday, March 7, 2016

Solaris / Linux: Change a text string inside file without using an editor

This is useful when we need to change string or sentence inside file without editing it with and editor like vi or vim.

Execute the following command script to change the desired string globally, in other words this syntax changes all corresponding strings inside file:

perl -pi -e 's/OLD_STRING/NEW_STRING/g' FILE

 

Example:

perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config

 

No comments:

Post a Comment