pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

20220228-delimitless.md (925B)


      1 If you have used `sed` then you have used the `/` delimiter
      2 ```
      3 sed s/foo/bar/g file
      4 ```
      5 
      6 You will also probably be aware the need to escape any slash in the string you're trying to match, for example matching `f/o/o` would be
      7 ```
      8 sed s/f\/o\/o/b\/a\/r/g file
      9 ```
     10 
     11 What you may not know is you can use different delimiters to save yourself escaping any occurrence of slash in the string.
     12 
     13 ```
     14 sed s%foo%bar%g file
     15 sed 's|foo|bar|g' file
     16 sed 's foo bar g' file
     17 ```
     18 
     19 Note that some delimiters require quotes.  Any occurrence of your chosen delimiter in the string will have to be escaped.
     20 
     21 According to section 4.3 of the `sed` Info document you should be able to use "any single character", giving you a lot of options to chose from in order to avoid all the escaping.  To read this section of the Info document incant
     22 ```
     23 info sed -n "regexp addresses"
     24 ```
     25 
     26 Do you have a preferred delimiter or do you like a bit of variety?