Show HN: I wrote a book on GNU grep and ripgrep
My book on "GNU grep and ripgrep" is free to download today and tomorrow [1][2]
Code snippets, example files and sample chapters are available on GitHub [3]
The book uses plenty of examples and regular expressions are also covered from scratch. The book is suitable for beginners as well as serves as a reference. Hope you find it useful, I would be grateful for your feedback and suggestions.
I used pandoc+xelatex [4] to generate the pdf.
[1] https://gumroad.com/l/gnugrep_ripgrep
[2] https://leanpub.com/gnugrep_ripgrep
[3] https://github.com/learnbyexample/learn_gnugrep_ripgrep
[4] https://learnbyexample.github.io/tutorial/ebook-generation/c...
54 comments
[ 4.5 ms ] story [ 132 ms ] threadhttp://jlebar.com/2012/11/28/GNU_grep_is_10x_faster_than_Mac...
[1] https://unix.stackexchange.com/questions/398223/grep-strange...
[2] https://unix.stackexchange.com/questions/352977/why-does-thi...
[1] https://blog.burntsushi.net/ripgrep/
I didn't have a scientific testing setup though. I just ran them one by one like this:
time cat title_complete_json.txt | grep tt9184994 >> result
time grep tt9184994 < title_complete_json.txt >> result
time grep tt9184994 title_complete_json.txt >> result
Not useless at all.
Thanks for your tip, it's clearly the best of both worlds for this purpose.
In pretty much any case involving more complicated queries and/or unicode I have found rg to be the fastest by a very wide margin. Also if you're searching multiple files rg is multithreaded by default without having to pass through something like xargs or parallel. If you're just searching for an ASCII string literal in a single file rg probably gets slowed down by its UTF-8 validation.
> If you're just searching for an ASCII string literal in a single file rg probably gets slowed down by its UTF-8 validation.
This is most definitely wrong. Firstly, ripgrep doesn't do any UTF-8 validation. That would make it much much slower. Secondly, searching a simple literal is one of the cases where ripgrep should actually do better than GNU grep in many cases. This is because of the slightly smarter way in which ripgrep keeps its vectorized loop active more often than GNU grep does by trying to search rarer bytes. I talk about this quite a bit here, which even includes a benchmark where I measured ripgrep at 2x the speed of GNU grep for a simple literal search: https://blog.burntsushi.net/ripgrep/#subtitles-literal
Anyone can try this for themselves:
On my system, /tmp is a ramdisk, so this doesn't factor in I/O. If you look up this thread, you'll note that someone was trying to search a 30GB file. Unless that person could fit that file into memory, it's very likely that they were just measuring the I/O bandwidth of their machine.I would try to get as small an output as possible, and not hit the file system at all, for example by using
> ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern
I'm not sure if many other people would jump to similar conclusions. So the readme might not really need a revision.
Thanks, already learned a few new things which will be handy in future.
Of course, that might lead to "crowdsourced" editing, which might be a horrible thing to create.
Lots of the missing articles are around command line arguments, where the correct usage is ambiguous anyway.
I don't find it distracting. The content of these books is an excellent resource on an immeasurably useful topic.
As for "... but if you're asking for money...," this post is literally giving away his work. The consumer is given the option to pay nothing, or whatever is reasonable according to their own valuation.
If you as the consumer value the work less because it fails to conform to language rules, then you are actually invited to decrease the compensation given by you to the author.
What was your writing process, and did you make any arrangements before getting started?
One of my forever back-burner projects is a deep(ish) dive like this into one of the tools that a lot of us kind of know how to use. I'm glad to see you went and did it!
My case is kinda weird one. I left my job after just 6 years in corporate world, due to various reasons. To cut a long story short, I went through depression, trying various things which didn't work out, etc. I conduct basic cli/scripting workshops at college, so I tried improving my materials - got active on stackoverflow, reddit, etc and started maintaining repos on github [1] It grew and finally last year I got the courage to try and self publish my tutorials collected for 2+ years in the form of books.
'deep dive' is a nice way to sum it up, it is amazing that there's so much to write about a tool. I knew probably about 5-10 grep options when I was at my job, and didn't know regular expressions that well. So, being able to write a book with confidence is such a satisfying experience. I still have plenty to improve (as can be observed from feedback in this thread) and I look forward to writing many more books.
One simple advice I can give you is start maintaining notes for the tool you are interested in. May be blog post or a repo, that way you can share with others and get feedback. Keep adding one command at a time and in a few months you'll have plenty to write about. Good luck!
[1] https://github.com/learnbyexample
BSD tail: https://searchcode.com/codesearch/view/457515/
GNU tail: https://github.com/coreutils/coreutils/blob/master/src/tail....
Usually the BSD one is short and sweet and the GNU one is a bit complex.
GNU utilities may be high performance but they tend to be hard to understand.
It's not just about performance. It's also about portability. GNU utilities are intended to work on various nixen rather than just GNU/Linux.
I mean, hell, the GNU tail you link to includes an explicit workaround for odd select() behavior on AIX.
also, do you mean that one shouldn't make money by using free software which gives the freedom to make money?
Programming languages like Python and Ruby are also free software that come with documentation. Should books written for those languages also come with free license?
Are there plan on making the solutions to the exercise available? I'm stuck on this question:
I'd prefer to help readers with hints rather than making solutions public. Give it your best shot and if you are stuck with no where to go, you can contact me via email/twitter mentioned in Preface chapter.
Hint for this question: there are multiple possible solutions. I used -P option for its skipping feature (see 'Perl Compatible Regular Expressions' chapter) to avoid the code blocks.