Hello! Here are some awesome deals for programming books and courses during the 2025 festive season. My ebooks 🔗 Festive offers for my ebooks till 30-November-2025: All 13 Books Bundle — $16 (normal price $36), learn Regular Expressions, Linux CLI tools, Python, Vim and more! Understanding Python re(gex)? — FREE (normal price $10) Other deals 🔗 Python related deals The Pragmatic Bookshelf — 50%…
From wikipedia: Connect Four : Connect Four is a game in which the players choose a color and then take turns dropping colored tokens into a six-row, seven-column vertically suspended grid. The pieces fall straight down, occupying the lowest available space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own…
This blog post gives an overview and examples of regular expression syntax as implemented by the re built-in module (Python 3.13+). Assume ASCII character set unless otherwise specified. This post is an excerpt from my Understanding Python re(gex)? book. Visualization created using debuggex for the pattern r'\bpar(en|ro)?t\b' From docs.python: re : A regular expression (or RE) specifies…
Do you find it confusing to use Ctrl+r for searching a command from shell history? I have the following mappings in the ~/.inputrc file, so that I can use the ↑ and ↓ arrow keys instead. Note that this assumes you are using Emacs-style key bindings instead of Vi mode. "\e[A" : history-search-backward "\e[B" : history-search-forward Normally, when you use the ↑ arrow key, you'll get the…
Either you've already heard of pandoc or if you have searched online for markdown to pdf or similar, you are sure to come across pandoc . This tutorial will help you use pandoc to generate pdf and epub versions from a GitHub style markdown file. The main motivation for this blog post is to highlight the customizations I used for self-publishing my ebooks . It wasn't easy to arrive at the…
The command name sed is derived from s tream ed itor. The most commonly used editing command is substitution , for which various examples are shown in this blog post. The examples presented here have been tested with GNU sed . Syntax and features might differ for other implementations. Basic Substitution 🔗 The substitute command syntax is s/REGEXP/REPLACEMENT/FLAGS where: s stands…
Hello! I am pleased to announce a new version of my CLI text processing with GNU awk ebook. Learn the GNU awk command step-by-step from beginner to advanced levels with hundreds of examples and exercises . This book will dive deep into field processing, show examples for filtering features, multiple file processing, how to construct solutions that depend on multiple records, how to compare records…
Do you find awk one-liners cryptic? Stuff like !a[$0]++ , 1 , $1=$1 , NR==FNR and -v RS= ? You'll find examples and brief explanations for such idioms in this post. The examples presented here have been tested with GNU awk . These are likely to work with most other implementations of awk as well. awk command structure 🔗 awk 'cond1{action1} cond2{action2} ... condN{actionN}' When a…
I prefer stability and thus I let my Linux LTS distributions to last almost till the entire end of support time. Having learned from previous transition periods, I started maintaining notes on what softwares I install/purge and some of the customization stuff. This has vastly reduced the pain of a fresh OS installation, but the fact remains that there'll always be some persistent and…
Hello! I just published a new version of my Understanding Python re(gex)? ebook. This book will help you learn Python Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises . The standard library re as well as the third-party regex module are covered in this book. Release offers 🔗 To celebrate the new release, you can download the PDF/EPUB…
You might already know how to use the --color option to highlight matched portions with GNU grep . In this post, you'll see how to use ANSI escape sequences to format matched portions with GNU sed and GNU awk . GNU grep 🔗 Consider this sample input file: $ cat fruits.txt banana mango cherry pineapple grape fig apple dragonfruit papaya watermelon cashew tomato orange almond lime grapefruit…
Hello! I am pleased to announce a new version of my 100 Page Python Intro ebook. This book is a short, introductory guide for the Python programming language. This book is well suited: As a reference material for Python beginner workshops If you have prior experience with another programming language If you want a complement resource after reading a Python basics book, watching a video course, etc…
Hello! Here are some awesome deals for programming books and courses during the 2024 festive season. My ebooks 🔗 Offers valid till 02-Dec-2024. You can get them on Leanpub: All 13 Books bundle — $15 (normal price $32), learn Regular Expressions, Linux CLI tools, Python, Vim and more! Linux CLI Text Processing bundle — $10 (normal price $20), grep, sed, awk, perl and ruby one-liners, GNU…
Having an interactive program that automatically loads questions and checks the solution is wonderful to have while learning a topic. This TUI app has beginner to intermediate level exercises and multiple-choice questions for Python learners. Installation 🔗 This app is available on PyPI as pythonexercises . Example installation instructions are shown below, adjust them based on your preferences…
Hello! I am pleased to announce a new version of my Vim Reference Guide ebook. This is intended as a concise learning resource for beginner to intermediate level Vim users. It has more in common with cheatsheets than a typical text book. Topics like Regular Expressions and Macros have more detailed explanations and examples due to their complexity. I hope this guide would make it much easier for…
I rarely ever use the date command, but when I need it I almost always struggle to get the right incantation. So, I'm just going to record such examples in this blog post (and some good to know features). There'll also be learning resources linked at the end of the post. Really basic examples The date command by itself shows the current time. But that's rarely what I need, since I…
Hello! I am pleased to announce a new version of my Linux Command Line Computing ebook. This is the longest book I've published so far (204 pages) — it took me more than 7 months to complete the first version and another month for a minor revision. This ebook aims to teach Linux command line tools and Shell Scripting for beginner to intermediate level users. The main focus is towards managing…
Know command line basics and want to learn the GNU awk command? Check out my interactive TUI app that gives a brief tour of this popular text processing command. Installation 🔗 This app is available on PyPI as awktutorial . Example installation instructions are shown below, adjust them based on your preferences and OS. # virtual environment $ python3 -m venv textual_apps $ cd textual_apps $…
I'm hoping this post will serve as a quick reference for some of the use cases and tickle your curiosity if you haven't come across this nifty CLI text processing tool yet. There are also links for further reading at the end. Installation and Documentation 🔗 See download page for source code and instructions to install the software on various platforms. This blog post is based on the…
Hello! I am pleased to announce a new version of my CLI text processing with GNU Coreutils ebook. Examples, descriptions and external links were updated/corrected and 100+ exercises were added. You might be already aware of popular coreutils commands like head , tail , tr , sort and so on. This book will teach you more than twenty of such specialized text processing tools provided by the GNU…
Hello! I am pleased to announce a new version of my Ruby One-Liners Guide ebook. Examples, exercises, solutions, descriptions and external links were added/updated/corrected. When it comes to command line text processing, there are several well known tools like grep for filtering, sed for substitution and awk for field processing. Compared to such tools, Ruby has a feature rich regular…
Hello! I just published a new version of the " Understanding Ruby Regexp " ebook. Corrected examples and descriptions for Atomic grouping, \G and \K features, improved examples, exercises and so on. This book will help you learn Ruby Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises . Ebook links 🔗 You can download the PDF/EPUB versions…
TL;DR : Updated six programming ebooks, created four interactive TUI apps for exercises, wrote blog posts, recorded YouTube videos, newsletter prospered, read 100+ novels, and so on. Had a great year in terms of ebook sales despite worries over AI tools 😇 Books updated 🔗 This year I focused on updating my existing ebooks instead of working on a new one. I managed to revise 6 out of my 13…
Hello! Here are some exciting deals for my programming ebooks as well as from other creators. My ebooks 🔗 Offers valid till 30-Nov-2023: All 13 Books Bundle — $10 (normal price $32) Learn by example Python bundle — $4 (normal price $15) Understanding Python re(gex)? — FREE (normal price $10) Indie creators 🔗 Python Problem-Solving Bootcamp — 40% off or purchasing power parity discount whichever…
Hello! I just published a new version of " Understanding JavaScript RegExp " ebook. Added examples for d and v flags, corrected many mistakes, improved examples, exercises and so on. This book will help you learn JavaScript Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises . Release offers 🔗 To celebrate the new release, you can download…
I'm finally writing a post on the ed command. And I'm keeping it short so that I'll actually publish the post. The examples presented below will be easier to understand for those already familiar with Vim and sed . See the links at the end for learning resources. Although I'm interested in getting to know ed better, I don't really find myself in situations where it'd…
Hello! I am pleased to announce a new version of my Perl One-Liners Guide ebook. Examples, exercises, solutions, descriptions and external links were added/updated/corrected. When it comes to command line text processing, there are several well known tools like grep for filtering, sed for substitution and awk for field processing. Compared to such tools, Perl has a feature rich regular…
Combining motions such as w , % and f with editing commands like d , c and y require precise positioning to be effective. Vim also provides a list of handy context based options to make certain editing use cases easier using the i and a text object selections. You can easily remember the difference between these two options by thinking i as inner and a as around . diw delete a word regardless of…
Here are some text and indent Vim settings that you can put in the vimrc file to customize your editor. See :h options.txt for complete reference. filetype plugin indent on enables loading of plugin and indent files these files become active based on the type of the file to influence syntax highlighting, indentation, etc :echo $VIMRUNTIME gives your installation directory ( indent and plugin…
sed provides escape sequences to change the case of replacement strings, which might include backreferences, shell variables, etc. Sequence Description \E indicates the end of case conversion \l convert the next character to lowercase \u convert the next character to uppercase \L convert the following characters to lowercase (overridden by \U or \E ) \U convert the following characters to…
In an earlier tip , you learned how to sort iterables based on a key. You can use a sequence like list or tuple to specify a tie-breaker condition when two or more items are deemed equal under the primary sorting rule. >>> books = ( 'Mage Errant' , 'Piranesi' , 'Cradle' , 'The Weirkey Chronicles' , 'Mistborn' ) # sorts based on the number of words # retains original order for items with the same…
You can save frequently visited locations using marks for quicker navigation to those positions in the file. You can also pair marks with motion commands for tasks like copying, deleting, etc. ma mark location in the file using the alphabet a you can use any of the 26 alphabets use lowercase alphabets to work within the current file use uppercase alphabets to work from any file :marks will show a…
awk is handy to compare records and fields between two or more files. The key features used in the solution below: For two files as input, NR==FNR will be true only when the first file is being processed next will skip rest of the script and fetch the next record a[$0] by itself is a valid statement. It will create an uninitialized element in array a with $0 as the key (assuming the key…
Having an interactive program that automatically loads questions and checks the solution is immensely helpful to have while learning a topic. I've written TUI apps with plenty of beginner to intermediate level exercises for GNU grep , GNU sed and GNU awk . Installation 🔗 For the past few months, I've been using a Python framework called Textual to create interactive TUI apps.…
Lookarounds help to create custom anchors and add conditions within a regex definition. These assertions are also known as zero-width patterns because they add restrictions similar to anchors and are not part of the matched portions. Negative lookarounds were discussed in this post . The syntax for positive lookarounds is shown below: (?=pat) positive lookahead assertion (?<=pat) positive…
Here are some general Vim settings that you can put in the vimrc file to customize your editor. See :h options.txt for complete reference. set history=200 increase default history from 50 to 200 there are separate history lists for : commands, search patterns, etc set nobackup disable backup files set noswapfile disable swap files colorscheme murphy a dark theme you can use :colorscheme followed…
The paste command is typically used to merge two or more files column wise. By default, paste adds a tab character between corresponding lines of input files. $ cat colors_1.txt Blue Brown Orange Purple $ cat colors_2.txt Black Blue Green Orange $ paste colors_1.txt colors_2.txt Blue Black Brown Blue Orange Green Purple Orange You can use the -d option to change the delimiter between the columns.…
The next() builtin function can be used on an iterator (but not iterables) to retrieve the next item. Once you have exhausted an iterator, trying to get another item will result in a StopIteration exception. Here's an example: >>> names = (m for m in dir ( tuple ) if '__' not in m) >>> next (names) 'count' >>> next (names) 'index' >>> next (names) Traceback (most recent call last): File…
Quantifiers can be applied to literal characters, dot metacharacter, groups, backreferences and character classes. * match zero or more times abc* matches ab or abc or abccc or abcccccc but not bc Error.*valid matches Error: invalid input but not valid Error s/a.*b/X/ replaces table bottle bus with tXus since a.*b matches from the first a to the last b \+ match one or more times…
The grep command provides the -o option to extract only the matching portions. Here are some examples using the BRE/ERE regexp flavors: # whole words made up of lowercase alphabets and digits only $ s= 'coat Bin food Apple (tar12) best fig_42' $ echo "$s" | grep - owE '[a-z0-9]+' coat food tar12 best # extract characters from the start of string based on a delimiter $ echo…
You can use the zip() builtin function to iterate over two or more iterables simultaneously. In every iteration, you'll get a tuple with an item from each of the iterables. Here's an example: >>> names = [ 'Joe' , 'Mei' , 'Rose' , 'Ram' ] >>> physics = [ 86 , 91 , 76 , 80 ] >>> maths = [ 77 , 92 , 81 , 83 ] >>> for n, p, m in zip (names, physics, maths): ... print ( f ' {n :5 } : {p} ,…
Hello! I am pleased to announce a new version of my CLI text processing with GNU sed ebook. Examples, exercises, solutions, descriptions and external links were added/updated/corrected. This book will help you learn the GNU sed command step-by-step from beginner to advanced levels with hundreds of examples and exercises . In addition to command options, regular expressions will also be…
Moving within the visible window: H move to the first non-blank character of the top (home) line of the visible window M move to the first non-blank character of the middle line of the visible window L move to the first non-blank character of the bottom (low) line of the visible window Reposition the current line: Ctrl + e scroll up by a line Ctrl + y scroll down by a line zz reposition the…
In awk , the FS variable allows you to define the input field separator . In contrast, FPAT (field pattern) allows you to define what should the fields be made up of. $ s= 'Sample123string42with777numbers' # one or more consecutive digits $ echo "$s" | awk - v FPAT = '[0-9]+' '{print $2}' 42 $ s= 'coat Bin food tar12 best Apple fig_42' # whole words made up of lowercase alphabets and digits only $…
Lookarounds help to create custom anchors and add conditions within a regex definition. These assertions are also known as zero-width patterns because they add restrictions similar to anchors and are not part of the matched portions. The syntax for negative lookarounds is shown below: (?!pat) negative lookahead assertion (?<!pat) negative lookbehind assertion Here are some examples: # change 'cat'…
By default, regexp matches anywhere in the text. You can use line and word anchors to specify additional restrictions regarding the position of matches. These restrictions are made possible by assigning special meaning to certain characters ( metacharacters ) and escape sequences. ^ restricts the match to the start-of-line ^This matches This is a sample but not Do This $ restricts the match to the…
By using the g flag with the s command (substitute), you can search and replace all occurrences of a pattern. Without the g flag, only the first matching portion will be replaced. Did you know that you can use a number as a flag to replace only that particular occurrence of matching parts? # replace only the third occurrence of ':' with '---' $ echo 'apple:banana:cherry:fig:mango' | sed…
Python provides a wide variety of features to work with strings. In this tip, you'll learn about string concatenation and repetition. The + operator is one of the ways to concatenate two strings. The operands can be any expression that results in a string value and you can use any of the different ways to specify a string literal. Another option is to use f-strings. Here are some examples:…
You can execute external commands from within Vim. Here are some examples: :!ls execute the given shell command and display output the results are displayed as part of an expanded Command-line area, doesn't change contents of the file :.!date replace the current line with the output of the given command pressing !! in Normal mode will also result in :.! ! waits for motion similar to d and y…
Hello! I am pleased to announce a new version of my CLI text processing with GNU grep and ripgrep ebook. Examples, exercises, solutions, descriptions and external links were added/updated/corrected. The chapter on ripgrep was changed significantly to focus mostly on the differences compared to GNU grep . This book will help you learn these commands step-by-step from beginner to advanced…