Basic sed usage : shell
By Asim Krishna Prasad
Posted on 26/11/14
Tag :
Shell
In this post we are going to see some basic examples of sed
We'll first use sed to replace a word in a text file..
By default sed is case sensitive (we'll see how to make it case in-sensitive)..
A basic syntax is = 's/WordToBeReplaced/WordToBePlanted/g'
We'll see some more sed commands and pattern flags later..
In the following examples we are going to replace instances of "this" with "REPLACED" and observe the different outputs when we make slight changes
Example-1
sed 's/this/REPLACED/g' test.txt
sed 's/This/REPLACED/g' test.txt
It is now clear from the above example how the sed is case-sensitive
Now let us make it case insensitive, for which we'll use i command
Example-2
sed 's/THIS/REPLACED/i' test.txt
NOTE : The changes are not getting saved in the source file .. We'll see in the following posts how to save these changes in the file.
Hope it helps :)
Asim Krishna Prasad
COMMENTS :