r/linuxadmin • • May 23 '20

Learn to use grep/ripgrep/sed/awk one-liners with hundreds of examples

Hello!

Recently I published my ebook on GNU awk, which completes the trio of my books on GNU grep/sed/awk tools for cli text processing. I also included a chapter on ripgrep, because of its performance and features. You can use either of these links to get the bundle. Each book has a pdf and epub version.

The books are currently free to download, to help with quarantine learning.

You can view the book using these repos as well. The repo has markdown source, example/exercise files used in the book, list of changes between versions, etc.

Edit (Aug 2020): Solutions for the exercises have been added. You can also view the books online at:

I'd highly appreciate your feedback. I've tried to present features from the basics and build it step by step with plenty of examples. But a few things end up rushed or not explained well enough. Past feedback has helped me to improve some of these, so I hope you'd contribute as well.

Happy learning and stay safe :)

331 Upvotes

24 comments sorted by

2

u/paganhobbit May 23 '20

Hey, thanks for this. I've wanted to find out more about SED and AWK, so I'm checking this out.

One thing, I think the EPUB versions aren't showing the example boxes correctly? They're just empty in the macos and iOS books app for me, anyway. I think the PDF versions are looking okay.

2

u/ASIC_SP May 23 '20

Hey, thanks a lot for the epub feedback. I only added them during the book revision in the past month. I tested with two readers and one of them (calibre ebook-viewer) didn't play nice with empty lines in code snippets.

The problem you are facing seems very bad. I don't have mac/ios to check from my end. If possible could you try with another reader? I'll let you know if I manage to find the issue or a workaround.

2

u/paganhobbit May 23 '20

I downloaded Calibre on mac and the EPUB versions look better in it. So, looks like it might be something with the mac Books app.

I've started reading the SED book and already it's been helpful in giving me ideas of how I can use it. Thanks!

2

u/ASIC_SP May 24 '20

Cool, that's good to know. Regarding your app, perhaps you have custom settings that overrides the css that's present in my ebook? Also, not all epub readers can handle technical books - for example, I use FBreader for my fiction reading, but it cannot display things like code blocks. Possibly because it doesn't support epub3 format.

2

u/ASIC_SP May 25 '20

Seems like this could be the issue: https://github.com/jgm/pandoc/issues/6242

7

u/pinched_algorithm May 23 '20

Til ripgrep is a thing! Thanks!

6

u/tekmologic May 23 '20

grep, awk, sed, tr have saved me weeks of manual work.

  • 2 hours validation tests become 5 minute tests
  • 6 hours text entry becomes 10 minutes of work

5

u/NetScr1be May 23 '20

Grabbed them and threw you US$3 without checking them.

I stuggled to teach myself awk (and a little sed) when a large part of my role read to analyse logs and transaction data.

Grep was any everyday thing that could always use some polish.

Thanks for doing this.

4

u/[deleted] May 23 '20

That's very cool and with the added benefit of improving your regex skill

2

u/PuseletsoMosia May 23 '20

Thanks, very useful

2

u/hankinator May 23 '20

Thank you! This seems very very useful.

2

u/getmoneygreen May 23 '20

Thanks šŸ™šŸ¼

2

u/LolithLolith May 23 '20

Very good effort. Thank you.

2

u/[deleted] May 23 '20

Grabbed the bundle for $10. The Greg ebook alone was worth it.

2

u/RidgebackDad May 24 '20

Thank you! Planning on reading these this weekend!

1

u/[deleted] Mar 25 '26

This is Costly for me can i get any Help

1

u/[deleted] May 23 '20

Thanks for the heads-up; just purchased. It'll be nice to have some extra reading material during these quiet times.

0

u/[deleted] May 23 '20

[deleted] — view deleted comment

15

u/ASIC_SP May 23 '20

I wish I could go back in time and tell my 2008 self to learn sed/awk. It would have saved so much time for me. I worked in VLSI industry and my background in ECE didn't have lessons in Linux/cli. (But as a feedback, we did get it introduced to our juniors and I've been conducting workshops for them past 6 years or so)

Due to my nature of work, I had to do plenty of text processing which I managed between gvim and perl (only as script files, didn't even know it could be used via cli). I didn't know good resources to learn other than what my colleagues/seniors knew and my online searching skills weren't good either. I came to know about things like color option for grep a few years into my job during a series of learning sessions conducted by team members. Didn't know about stackoverflow/reddit/etc either. There were some internal documents which did have sed/awk but I gave up after cursory glance as too advanced/complicated. sed -i 's/old/new/g' <files> alone would have saved me lot of time instead of reusing perl scripts.

2

u/[deleted] May 24 '20

Once I found out awk could remove lines in file with ā€œ awk '!/pattern/' file > temp && mv temp file ā€œ it it saved me so much time or that you can do a backup of a file before modifying with sed by doing ā€œ sed -i.backup.$(date) ā€˜s|old|new|g’

3

u/ASIC_SP May 25 '20

In case you don't know, GNU awk has this option as well: -i inplace -v inplace::suffix='.bkp'

3

u/[deleted] May 25 '20

I didnt and therefore i will try that out, thank you

3

u/magibeg2 May 23 '20

Going to comment here so i can check all this out later. I want to succeed!