Just picked up a little bit of sed kungfu today while pairing with jeff.
In-place editing with “-i”
If you want to do in-place editing of a file, you can pass the
-i option to sed. Let’s say we have the following file:
1
| |
With:
1
| |
We get:
1
| |
So how do i acheive this previously ?? This is embarrassing, it used to be like this:
1 2 | |
Replacing only lines matching pattern
Let’s say you have the following file:
1 2 | |
We want to replace only the line with the occurrence of “sed”. We
can acheive it using the script command
/<pattern>/s/<original-text>/<replacement-text>, just like this:
1
| |
This is what we get in stdout:
1 2 | |
Happy Sed-ing :)