Skip to content

Commit 8c5e3c3

Browse files
committed
Add Use An Alternative Delimiter In A Substitution as a sed til
1 parent d01f57b commit 8c5e3c3

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1212

13-
_1065 TILs and counting..._
13+
_1066 TILs and counting..._
1414

1515
---
1616

@@ -48,6 +48,7 @@ _1065 TILs and counting..._
4848
* [React Testing Library](#react-testing-library)
4949
* [ReasonML](#reasonml)
5050
* [Ruby](#ruby)
51+
* [sed](#sed)
5152
* [Shell](#shell)
5253
* [Tailwind CSS](#tailwind-css)
5354
* [tmux](#tmux)
@@ -923,6 +924,10 @@ _1065 TILs and counting..._
923924
- [Wrap Things In An Array, Even Hashes](ruby/wrap-things-in-an-array-even-hashes.md)
924925
- [Zero Padding](ruby/zero-padding.md)
925926

927+
### sed
928+
929+
- [Use An Alternative Delimiter In A Substitution](sed/use-an-alternative-delimiter-in-a-substitution.md)
930+
926931
### Shell
927932

928933
- [Check If The First Argument Is Given](shell/check-if-the-first-argument-is-given.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Use An Alternative Delimiter In A Substitution
2+
3+
A pretty standard sed substitution command is going to use `/` (the forward
4+
slash) as the delimiter. The delimiter separates the different parts of the
5+
command.
6+
7+
```bash
8+
$ sed 's/critter/creature/' animals.txt
9+
```
10+
11+
The first delimiter marks the beginning of the regular express to be replaced.
12+
That expression is everything up to the next delimiter. Then the substute
13+
expression starts up until the next delimiter.
14+
15+
There is nothing special about the `/` as the delimiter, it just happens to be
16+
the most commonly used character.
17+
18+
In fact, any visible character can be used as the delimiter with sed.
19+
20+
Some other common ones are `:`, `|`, and `_`. I like how the `pipe` character
21+
looks.
22+
23+
```bash
24+
$ sed 's|critter|creature|' animals.txt
25+
```
26+
27+
But like I said, any visible character will work. If you wanted, you could use
28+
`Q` though that'll look strange and could cause some confusion when reading
29+
through your script.
30+
31+
```bash
32+
$ sed 'sQcritterQcreatureQ' animals.txt
33+
```

0 commit comments

Comments
 (0)