Live data from Hacker News

Using different delimiters in sed (2010)

backreference.org

11–20 of 30 posts

Re: Using different delimiters in sed (2010)

#11
post #6
post #5

Earlier quoted context omitted.

> 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.

Yes, 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.

My 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.

Re: Using different delimiters in sed (2010)

#12
post #4

The common alternate character, for those cases where normal slashes are not suitable, is a comma character; ‘,’. With Sed code, readability is always an issue, and it can be improved by not using just any character and limiting yourself to as few alternative modes of syntax as possible. With a bit of exposure, commands like s/foo/bar/ and s,foo,bar, can be read with equal ease.

I tend to use : as the alternate delimiters.

Re: Using different delimiters in sed (2010)

#16
post #5
post #4

The common alternate character, for those cases where normal slashes are not suitable, is a comma character; ‘,’. With Sed code, readability is always an issue, and it can be improved by not using just any character and limiting yourself to as few alternative modes of syntax as possible. With a bit of exposure, commands like s/foo/bar/ and s,foo,bar, can be read with equal ease.

> 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.

Doesn’t that confuse you because it is the alternation symbol (https://regular-expressions.mobi/alternation.html) in many, if not all, regular expression syntaxes?

Re: Using different delimiters in sed (2010)

#17
post #14

On a related note, I found Bruce Barnett's sed tutorial is one of the best Sed guide out there: http://www.grymoire.com/Unix/Sed.html

It was really good, thank you! I learned a ton of new tricks from it

Separately, I feel like I could have a full time job submitting PRs to fix the GNU-ism of using `sed -i"" ...` versus the BSD/macOS syntax of `sed -i "" ...`. I don't know which of those two camps broke from the other, but holy hell it _broke_ for sure.

Re: Using different delimiters in sed (2010)

#18
I’ve seen so many hilariously bad workarounds for this in old shell scripts from lazy engineers who apparently can’t read a man page and don’t realise the delimiter character is substitutable with more or less any character you like.

This is one of this extremely useful features that a surprisingly large number of users don’t seem to know about.

Re: Using different delimiters in sed (2010)

#19
post #6
post #5

Earlier quoted context omitted.

> 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.

Yes, 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.

My 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.

Re: Using different delimiters in sed (2010)

#20
post #18

I’ve seen so many hilariously bad workarounds for this in old shell scripts from lazy engineers who apparently can’t read a man page and don’t realise the delimiter character is substitutable with more or less any character you like. This is one of this extremely useful features that a surprisingly large number of users don’t seem to know about.

Indeed. `/` covers 99% of my cases, `|` covers 99% of the remaining. I think i might have had to use something "exotic" once or twice in 30+ years now.
Post reply on HN