mirror of
https://github.com/chmln/sd
synced 2024-11-29 14:30:20 +00:00
Update readme
This commit is contained in:
parent
29c80fd6d7
commit
d8c806be82
1 changed files with 8 additions and 7 deletions
15
README.md
15
README.md
|
@ -20,7 +20,7 @@ Find & replace expressions are split up, which makes them easy to read and write
|
||||||
|
|
||||||
**Smart, common-sense defaults**
|
**Smart, common-sense defaults**
|
||||||
|
|
||||||
Smart-cased regular expressions also come with a sane syntax that's not opt-in. Defaults follow common sense and are tailored for typical daily use.
|
Defaults follow common sense and are tailored for typical daily use.
|
||||||
|
|
||||||
## Comparison to sed
|
## Comparison to sed
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ Some cherry-picked examples, where `sd` shines:
|
||||||
- `echo "sample with /path/" | sed -E 's/.*(/.*/)/\1/g'`
|
- `echo "sample with /path/" | sed -E 's/.*(/.*/)/\1/g'`
|
||||||
- `echo "sample with /path/" | sed -E 's|.*(/.*/)|\1|g'`
|
- `echo "sample with /path/" | sed -E 's|.*(/.*/)|\1|g'`
|
||||||
- In place modification of files:
|
- In place modification of files:
|
||||||
- sd: `sd -i before after file.txt`
|
- sd: `sd before after file.txt`
|
||||||
- sed: you need to remember to use `-e` or else some platforms will consider the next argument to be a backup suffix
|
- sed: you need to remember to use `-e` or else some platforms will consider the next argument to be a backup suffix
|
||||||
- `sed -i -e 's/before/after/g' file.txt`
|
- `sed -i -e 's/before/after/g' file.txt`
|
||||||
|
|
||||||
|
@ -134,6 +134,7 @@ In the unlikely case you stumble upon ambiguities, resolve them by using `${var}
|
||||||
```sh
|
```sh
|
||||||
> echo '123.45' | sd '(?P<dollars>\d+)\.(?P<cents>\d+)' '$dollars_dollars and $cents_cents'
|
> echo '123.45' | sd '(?P<dollars>\d+)\.(?P<cents>\d+)' '$dollars_dollars and $cents_cents'
|
||||||
and
|
and
|
||||||
|
|
||||||
> echo '123.45' | sd '(?P<dollars>\d+)\.(?P<cents>\d+)' '${dollars}_dollars and ${cents}_cents'
|
> echo '123.45' | sd '(?P<dollars>\d+)\.(?P<cents>\d+)' '${dollars}_dollars and ${cents}_cents'
|
||||||
123_dollars and 45_cents
|
123_dollars and 45_cents
|
||||||
```
|
```
|
||||||
|
@ -141,15 +142,15 @@ In the unlikely case you stumble upon ambiguities, resolve them by using `${var}
|
||||||
4. **Find & replace in a file**
|
4. **Find & replace in a file**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
> sd -i 'window.fetch' 'fetch' http.js
|
> sd 'window.fetch' 'fetch' http.js
|
||||||
```
|
```
|
||||||
|
|
||||||
That's it. The file is modified in-place.
|
That's it. The file is modified in-place.
|
||||||
|
|
||||||
To do a dry run:
|
To preview changes:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
> sd 'window.fetch' 'fetch' http.js
|
> sd -p 'window.fetch' 'fetch' http.js
|
||||||
```
|
```
|
||||||
|
|
||||||
5. **Find & replace across project**
|
5. **Find & replace across project**
|
||||||
|
@ -159,7 +160,7 @@ This example uses [fd](https://github.com/sharkdp/fd).
|
||||||
Good ol' unix philosophy to the rescue.
|
Good ol' unix philosophy to the rescue.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sd -i 'from "react"' 'from "preact"' $(fd -t f)
|
sd 'from "react"' 'from "preact"' $(fd -t f)
|
||||||
```
|
```
|
||||||
|
|
||||||
Same, but with backups (consider version control).
|
Same, but with backups (consider version control).
|
||||||
|
@ -167,6 +168,6 @@ Same, but with backups (consider version control).
|
||||||
```bash
|
```bash
|
||||||
for file in $(fd -t f); do
|
for file in $(fd -t f); do
|
||||||
cp "$file" "$file.bk"
|
cp "$file" "$file.bk"
|
||||||
sd -i 'from "react"' 'from "preact"' "$file";
|
sd 'from "react"' 'from "preact"' "$file";
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue