mirror of https://github.com/CrimsonTome/tldr.git
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
parent
a74d7f770e
commit
7328774d81
|
@ -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}}`
|
||||
|
|
Loading…
Reference in New Issue