Add struggles

This commit is contained in:
Gregory 2018-12-23 19:44:57 -05:00 committed by GitHub
parent c50407df22
commit fd5b592253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.