Live data from Hacker News

Using different delimiters in sed (2010)

backreference.org

1–10 of 30 posts

Re: Using different delimiters in sed (2010)

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

Re: Using different delimiters in sed (2010)

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

Re: Using different delimiters in sed (2010)

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

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.

Re: Using different delimiters in sed (2010)

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

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

Re: Using different delimiters in sed (2010)

#8
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 prefer

  @
because it is so weird and unexpected people are unlikely to misread the command and think it does something with multiple commands

tho perl’s qr (quote regex) operator is miles ahead, it even supports natural pairs of opening/closing delimiters

Re: Using different delimiters in sed (2010)

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

s,,,g is my favorite because it avoid /\//\\/ epilespy

Re: Using different delimiters in sed (2010)

#10
post #8
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 prefer @ because it is so weird and unexpected people are unlikely to misread the command and think it does something with multiple commands tho perl’s qr (quote regex) operator is miles ahead, it even supports natural pairs of opening/closing delimiters

I really like doing the following in Perl:

    s{/u/r/i}{do something}
Sadly doesn’t support that (or at least none of the sed’s I’ve used). So I fallback to using hash (#) instead (for no particular reason aside that’s what I’ve always used).
Post reply on HN