4 ms·
I was tempted to poke a little fun at you for having trouble with sed -- among my peers, 's/foo/bar/g' used pretty much daily, even just in informal emails/conv
by kevhito 10y ago
I was tempted to poke a little fun at you for having trouble with sed -- among my peers, 's/foo/bar/g' used pretty much daily, even just in informal emails/conversations.
But I'm glad I looked at the list first, because I found this wonder: `lstopo --of txt`. I'm going to use this in class next week, I can't believe I've never seen that before.
- linkregister 10y agoMy biggest hardship with sed is having to figure out how to escape the operators within regular expressions on the command line. I think it's pretty reasonable to spend 15+ minutes on a complicated replacement regex. Edit: It looks like I agree with you; `replace` only solves trivial problems that can easily be done with `sed`.
- userbinator 10y agoYou can use single quotes to escape everything except single quotes from the shell. Then use backslashes to escape single quotes where needed. If you haven't taken the time, I'd say it's well worth learning exactly how the shell escapes work. It's surprisingly simple and natural once you get used to it.
- linkregister 10y agoThanks for the advice; I should block some time to fully grok shell escapes. Even with single quotes, sed still requires escaping parentheses, + operators, and other operators that would otherwise be interpreted literally (but not all operators should be escaped). In the languages that I learned regexes this wasn't required.
- NathanOsullivan 10y agoThere's a command line switch -E for sed that gives you what we think of as "normal" regex escaping.
- linkregister 10y agoYou have saved me many hours of future command line hacking. Thanks!
- leni536 10y agoAlso sed can use other characters instead of / for separating fields, like using _ instead for / heavy stuff: sed -e 's_https://www\.example\.com/_/_g' I think it's nicer than: sed -e 's/https:\/\/www\.example\.com\//\//g'
- deleted 10y ago[deleted]
- camtarn 10y agoOh, the basic syntax is fine. I'm a Vim user ;) And even before that, s///g was also part of my slang. My issue is remembering how to invoke the command - whether it edits in place by default, what the order of arguments is, etc. To be fair, that's not necessarily that much easier with a dedicated replace command either.