Announcing learnbyexample weekly newsletter

Hello!

I'm excited to announce learnbyexample weekly newsletter, scheduled to be delivered every Friday.

This free newsletter will help you discover awesome programming resources. I'll primarily focus on resources related to Python, Linux, CLI tools, Regular Expressions and Vim. Sometimes, I'll also include other programming resources.

Practice Python Projects book announcement

Hello!

My "Practice Python Projects" ebook presents five beginner-to-intermediate level projects inspired by real world use cases:

To test your understanding and to make it more interesting, you'll also be presented with exercises at the end of each project. Resources for further exploration are also mentioned throughout the book.

GNU BRE/ERE cheatsheet and differences between grep, sed and awk

GNU BRE/ERE cheatsheet

Poster created using Canva

This post covers Basic Regular Expressions (BRE) and Extended Regular Expressions (ERE) syntax supported by GNU grep, sed and awk. You'll also learn the differences between these tools — for example, awk doesn't support backreferences within regexp definition (i.e. the search portion).

info info info The versions used in this post are 3.11 for grep, 4.9 for sed and 5.3.1 for awk. There has been a significant change in awk's regular expression engine from version 5.4 such as the support for shortest-match (non-greedy) quantifiers — these changes are not covered in this post. From GNU awk manual:

Release 5.4.0 of gawk introduced a new regular expression matching engine, named MinRX.

MinRX is fully compliant with the POSIX standard for Extended Regular Expressions (EREs), including the additional features needed by awk and gawk. It is also a little stricter that the original matchers are in terms of accepting valid regular expression syntax when specifying a regexp. (These restrictions apply to corner cases that should not come up in day-to-day use.)

Emulating regexp lookarounds in GNU sed

This stackoverflow Q&A got me thinking about various ways to construct a solution in GNU sed if lookarounds are needed.

info Only single line (with newline as the line separator) processing is presented here. Equivalent lookaround syntax with grep -P or perl is also shown for comparison. Cases where multiple lines and/or ASCII NUL characters are present in the pattern space is left as an exercise.

Search and replace tricks with ripgrep

ripgrep (command name rg) is a grep tool, but supports search and replace as well. rg is far from a like-for-like alternate for sed, but it has nifty features like multiline replacement, fixed string matching, PCRE2 support, etc. This post gives an overview of syntax for substitution and highlights some of the cases where rg is a handy replacement for sed.