Sed: adds replace before matching sample

Something I find myself doing more and more is to match on a line instead of trying to match all I want with `{{find}}`.

So in a file like:

```erl
{ riak_core, [ {
    {riak_ip, "127.0.0.1"},
    %% ...
}, 
   %% ...
]
```

Instead of replacing that ip by doing `sed 's/riak_ip,"127\.0\.0\.1/riak_ip,"$NEW_IP/'`, I do `sed '/riak_ip/s/127\.0\.0\.1/$NEW_IP'`.
waldyrious/alt-syntax
Leandro Ostera 2016-02-27 14:23:24 +01:00
parent a74d7f770e
commit 7328774d81
1 changed files with 4 additions and 0 deletions

View File

@ -6,6 +6,10 @@
`sed 's/{{find}}/{{replace}}/' {{filename}}`
- Replace the first occurrence on all lines matching a pattern:
`sed '/{{line_pattern}}/s/{{find}}/{{replace}}/'`
- Replace all occurrences of a string in a file, overwriting the file (i.e. in-place):
`sed -i 's/{{find}}/{{replace}}/g' {{filename}}`