You are not logged in.
Every once in a while I get overly focused on understanding something, and this is one I'm having a hard time googling. Could someone please explain to me what this does:
sed -e 's|/$||
As far as I can understand it's a substitution/removal with the delimiter changed to pipe. What exactly does it remove? $? /$? Something else? If it was backslash then $ would be removed, but forward slash? I've tried various echo tests but can't really figure it out.
Last edited by marius-arc (2016-08-24 12:59:56)
Offline
It removes any backslash forward slash which occurs at the end of a line.
Offline
doooooh
Thank you so much!
Offline
Just to understand why you didn't understand... would you understand the following?
sed "s/\/$//"
Last edited by Awebb (2016-08-24 11:15:54)
Offline
Just to understand why you didn't understand... would you understand the following?
sed "s/\/$//"
I had written a whole bunch trying to figure that one out, but in the end isn't it the same as the original one, only different delimiter?
That is assuming there is no difference between " and ' and with/without -e
Offline
Indeed, the delimiters are different, but it does the same. I'd say the difference between double quotes and single quotes is irrelevant to sed. You use single quotes, if you want to prevent shells like sh and bash from expanding variables (or trying to expand anything like $text as a variable) and prevent globbing (although I'm not sure about the existence of edge cases). My question was meant to see, whether you were only confused by the pipe delimiters.
EDIT: To clear this up, sed treats everything after the command (s in this case) as a delimiter. You could also write sed 's /$ ', although I'm not sure whether this is understood by every implementation. See: http://backreference.org/2010/02/20/usi … rs-in-sed/
EDIT: Since I feel like phrasing today: The first instance of the delimiter defines the delimiter for the rest of the expression. If your delimiter appears too often in your expression as part of the expression, consider using another symbol to minimize escaping. The pipe was chosen here, because the single quotes defuse the pipe.
Last edited by Awebb (2016-08-24 16:12:32)
Offline
Thanks for the explanation!
Offline