mirror of
https://github.com/chmln/sd
synced 2024-11-22 11:13:04 +00:00
Add struggles
This commit is contained in:
parent
c50407df22
commit
fd5b592253
1 changed files with 8 additions and 6 deletions
14
README.md
14
README.md
|
@ -18,13 +18,15 @@ Find & replace expressions are split up and in most cases unescaped, which contr
|
|||
|
||||
## Comparison to sed
|
||||
|
||||
Although `sed` has a nice regex syntax with `-r`, it is not portable and doesn't work on, say, MacOS or Solaris. Also, `sed` is far more powerful. Focusing on just finding and replacing allows `sd` to make this common task far more straightforward.
|
||||
|
||||
Some cherry-picked examples, where `sd` shines:
|
||||
- Replace newlines with commas:
|
||||
- `sed ':a;N;$!ba;s/\r/,/g'` vs
|
||||
- `sd -r '\r' ','`
|
||||
|
||||
|
||||
- sed: `sed ':a;N;$!ba;s/\r/,/g'` vs
|
||||
- sd: `sd -r '\r' ','`
|
||||
- Extracting stuff out of strings with special characters
|
||||
- sd: `echo "{((sample with /path/))}" | sd -r '\{\(\(.*(/.*/)\)\)\}' '$1'`
|
||||
- sed
|
||||
- incorrect, but closest I could get after 15 minutes of struggle
|
||||
- `echo "{((sample string also contains /path/))}" | sed 's/{((\.\*\(\/.*\/\)))}/\1/g'`
|
||||
|
||||
Note: although `sed` has a nicer regex syntax with `-r`, it is not portable and doesn't work on, say, MacOS or Solaris.
|
||||
|
||||
|
|
Loading…
Reference in a new issue