Live data from Hacker News

Useful sed scripts and patterns

github.com

1–10 of 124 posts

Re: Useful sed scripts and patterns

#3
Sed is probably the one tool I owe my career most to. I made a living mostly on it for a few years as an ops guy, and I didn't even know half of these use cases. The variable delimiter alone was such a beautifully thought out decision that made everything easier, that I likely would have never considered had I written it.

Re: Useful sed scripts and patterns

#8
Something I crave in the worst way is a sensible story for accumulating a “toolbox” of snippets and scripts and commands.

They don’t need to be ready to go, but ideally:

- natural language searchable

- add a small description

- CLI to search, examine, and copy

- not a plugin

- sync with a GitHub repo.

Re: Useful sed scripts and patterns

#9
There are a ton of little errors in this post (at the time of my leaving this comment, of course): the variable delimiter example is missing the close _, the first word example is missing the open ', and the except line 5 example is missing a space; meanwhile, these snippets will cause bad habits, such as thinking about "words" as "things involving letters", using -r instead of -E, and a massive knowledge gap with respect to appropriate use of semicolons... I'm also really confused as to why sed is suddenly "s" in one of the examples. This just isn't a very good reference, and I'm not sure if the author thinks about how "c" works, but it really needs a \ afterwards, no matter what the one specific version of sed you are using might allow :/. As someone who loves sed so much he nigh unto regrets how much he uses it: "beware".

FWIW, I'd argue that the path to true sed mastery eventually goes through the hold space, which isn't mentioned here. For some real fun, and an exercise that might change how you mentally model what sed is capable of, check out SedSokoban.

https://aurelio.net/projects/sedsokoban/

Re: Useful sed scripts and patterns

#10

Something I crave in the worst way is a sensible story for accumulating a “toolbox” of snippets and scripts and commands. They don’t need to be ready to go, but ideally: - natural language searchable - add a small description - CLI to search, examine, and copy - not a plugin - sync with a GitHub repo.

One of the best hackers I ever worked with turned me onto this method.

Use a flat text in the editor of your choice. Search as needed. Tags work because you can seach them. You delimit each section as a note. I do it like this

---

Next note

---

It seems limited and primative, you don't get any markup or fun stuff. But it's soooo good. There is nothing to break or update. Seach is the method I use most anyway in my other note taking apps.

And you wind up putting everything in there, including commands that you're staging to run. Those staged commands become snippets later.

Post reply on HN