File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
10
10
11
11
For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
12
12
13
- _ 1065 TILs and counting..._
13
+ _ 1066 TILs and counting..._
14
14
15
15
---
16
16
@@ -48,6 +48,7 @@ _1065 TILs and counting..._
48
48
* [ React Testing Library] ( #react-testing-library )
49
49
* [ ReasonML] ( #reasonml )
50
50
* [ Ruby] ( #ruby )
51
+ * [ sed] ( #sed )
51
52
* [ Shell] ( #shell )
52
53
* [ Tailwind CSS] ( #tailwind-css )
53
54
* [ tmux] ( #tmux )
@@ -923,6 +924,10 @@ _1065 TILs and counting..._
923
924
- [ Wrap Things In An Array, Even Hashes] ( ruby/wrap-things-in-an-array-even-hashes.md )
924
925
- [ Zero Padding] ( ruby/zero-padding.md )
925
926
927
+ ### sed
928
+
929
+ - [ Use An Alternative Delimiter In A Substitution] ( sed/use-an-alternative-delimiter-in-a-substitution.md )
930
+
926
931
### Shell
927
932
928
933
- [ Check If The First Argument Is Given] ( shell/check-if-the-first-argument-is-given.md )
Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments