Monday, October 30, 2017

Sed - Example guide

sed is a very useful stream editor to perform search and replace. Below are some useful tip

1. Usage

sed 's/apple/orange/' file

The above will look for first occurrence of apple and replace with orange in the file and send the output to stdout

2. Make changes to the file

sed -i 's/apple/orange/' file

add -i option will make changes to the file itself

3. All occurrence changes

sed -i 's/apple/orange/g' file

adding g mean global replacement

4. Escape single quote

sed -i 's/'\''apple'\''/orange/' file

You can use '\'' to escape a single quote.

No comments:

Post a Comment

Tomcat - removing server info

Below are the steps to remove Tomcat Server Information 1. Make sure Tomcat is not running 2. Navigate to "Tomcat Installation"...