1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Use An Alternative Delimiter In A Substitution as a sed til

This commit is contained in:
jbranchaud
2021-02-28 15:18:17 -06:00
parent d01f57b100
commit 8c5e3c39e4
2 changed files with 39 additions and 1 deletions

View File

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