3 ms·
> The common alternate character, for those cases where normal slashes are not suitable, is a comma character; ‘,’. I've always used "|" since it's so visually
by cyphar 8y ago
> The common alternate character, for those cases where normal slashes are not suitable, is a comma character; ‘,’.
I've always used "|" since it's so visually similar, and you always want to quote regular expressions anyway.
- teddyh 8y agoYes, I’ve seen the vertical bar character used for this too. But in my experience the comma character is more commonly used, and my point was that we should all try to use as commonly used syntax as possible. Therefore I encourage everybody to use the comma character as their usual alternative character in order for the world of Sed code to be slightly less confusing.
- ajross 8y agoMy experience, colored more by perl styles than sed per se, is that the vertical bar is the overwhelmingly typical usage, actually. It's what Wall picked for the examples in the camel book, for example.
- laumars 8y agoMy experience has been that there isn’t a de facto standard outside of /. Arguing that people must use some standard you’ve adopted is a little like saying people should use tabs instead of spaces.
- yiyus 8y agoUsing "|" can be confusing when the sed command is part of a pipeline. I agree with the other user that the comma character is more used. It is slightly easier to type too.
- Someone 8y agoDoesn’t that confuse you because it is the alternation symbol (https://regular-expressions.mobi/alternation.html https://regular-expressions.mobi/alternation.html) in many, if not all, regular expression syntaxes?
- michaelcampbell 8y agoIt's rare that I need a sedex with both paths and alternation, but if I do I'll use something other than / or |. That's the point of this article; if what you're using is going to hinder obviousness, USE SOMETHING ELSE. Because... you can.
- marcosdumay 8y agoAnd comma appears in repetition limits (like in /a{1,2}/). I don't see much difference.
- bonzini 8y agoRepetition in sed would be written \{1,2\}, it's unwieldy enough that it's rarely used.
- cyphar 8y agoGiven the whole "sed" vs "sed -E" distinction, I'd say most metacharacters are confusing anyway. Not to mention usually when I'm using "|", I'm going to be replacing paths and don't really use alternation that often.