diff --git a/README.md b/README.md index 70492d0..b356627 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1065 TILs and counting..._ +_1066 TILs and counting..._ --- @@ -48,6 +48,7 @@ _1065 TILs and counting..._ * [React Testing Library](#react-testing-library) * [ReasonML](#reasonml) * [Ruby](#ruby) +* [sed](#sed) * [Shell](#shell) * [Tailwind CSS](#tailwind-css) * [tmux](#tmux) @@ -923,6 +924,10 @@ _1065 TILs and counting..._ - [Wrap Things In An Array, Even Hashes](ruby/wrap-things-in-an-array-even-hashes.md) - [Zero Padding](ruby/zero-padding.md) +### sed + +- [Use An Alternative Delimiter In A Substitution](sed/use-an-alternative-delimiter-in-a-substitution.md) + ### Shell - [Check If The First Argument Is Given](shell/check-if-the-first-argument-is-given.md) diff --git a/sed/use-an-alternative-delimiter-in-a-substitution.md b/sed/use-an-alternative-delimiter-in-a-substitution.md new file mode 100644 index 0000000..fc79a89 --- /dev/null +++ b/sed/use-an-alternative-delimiter-in-a-substitution.md @@ -0,0 +1,33 @@ +# Use An Alternative Delimiter In A Substitution + +A pretty standard sed substitution command is going to use `/` (the forward +slash) as the delimiter. The delimiter separates the different parts of the +command. + +```bash +$ sed 's/critter/creature/' animals.txt +``` + +The first delimiter marks the beginning of the regular express to be replaced. +That expression is everything up to the next delimiter. Then the substute +expression starts up until the next delimiter. + +There is nothing special about the `/` as the delimiter, it just happens to be +the most commonly used character. + +In fact, any visible character can be used as the delimiter with sed. + +Some other common ones are `:`, `|`, and `_`. I like how the `pipe` character +looks. + +```bash +$ sed 's|critter|creature|' animals.txt +``` + +But like I said, any visible character will work. If you wanted, you could use +`Q` though that'll look strange and could cause some confusion when reading +through your script. + +```bash +$ sed 'sQcritterQcreatureQ' animals.txt +```