Useful sed scripts and patterns
11–20 of 124 posts
Re: Useful sed scripts and patterns
#12There 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 re…
Re: Useful sed scripts and patterns
#13https://gist.github.com/awhileback/1fffac899d9321a6a9ec15bc9...
Requires some ocr / pdf parsing / metadata tools, see the comments.
Re: Useful sed scripts and patterns
#14Something 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 ot…
Eventually I'd like to publish it as a microblog for such snippets ala commandlinefu.com, but priorities and laziness get in the way. :/
Re: Useful sed scripts and patterns
#15Something 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.
My linux only snippet manager: https://github.com/barbuk/snippy
Re: Useful sed scripts and patterns
#16sed -e s/a/A/ -e s/foo/BAR/ -e s/hello/HELLO/
I use -e often enough that I usually use -e whether I expect to use more than one expression or not. There's a reasonable chance that I will be going back into my history and will need to add another, which is easier if the first -e is already there.
Also, 'sed -e expr1 -e expr2' gives the same results as 'sed expr1 | sed expr2'. In both cases, the order of the expressions matter: later expressions may change things altered by the first.
$ echo foo | sed -e 's/f/g/' -e 's/goo/go/'
goRe: Useful sed scripts and patterns
#17Something 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.
Shell completions are essential for it, so I had to stumble through writing my own for Fish, but now that it's setup it's quite nice.
Re: Useful sed scripts and patterns
#18Something 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 ot…
Every now and then I start a new sheet, dropping off the stuff I've memorized.
Re: Useful sed scripts and patterns
#19Something 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 ot…
I have txt files for commands I want to remember for each OS I daily use (linuxcmds.txt, windowscmds.txt, maccmds.txt) and split them the same way you said but 5 dashes. Also keep txt files for install/setup notes for each os, links to every program I want to install in fresh installs, etc etc.
Text files work on every single OS/device, the format is stable, it’s easily searchable, easily shareable, and my entire 30 years of notes is measured in megabytes.
Re: Useful sed scripts and patterns
#20 sed '1~2p' file.txt #needs -n option
s '1,$ s/foo/bar/' file.txt #s --> sed and 1,$ --> 5,$
Many commands using `-r` do not need the option for the command used (for ex: `sed -r '/start/q'`). Also, using `-E` is preferred instead of `-r` since some of the other implementations support this option but not `-r`.---
I wrote a book on GNU sed with plenty of examples and exercises: https://github.com/learnbyexample/learn_gnused It is free to read online and there's a detailed chapter for learning BRE/ERE regex flavor as well.