Beginner to Intermediate level projects inspired by real world use cases| learnbyexample.github.io
Learn Python, Regex, Linux, Scripting, Vim, Ebooks, Self-Publishing and Interesting Tech Nuggets.| learnbyexample.github.io
Connect Four TUI app in Python using textual.| learnbyexample.github.io
Overview and examples of Python regular expression syntax as implemented by the re built-in module| learnbyexample.github.io
Using .inputrc to remap key bindings for cli history search.| learnbyexample.github.io
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.| learnbyexample
Examples for search and replace with GNU sed.| learnbyexample.github.io
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.| learnbyexample
There is always some annoying troubleshooting to do when installating an Operating System.| learnbyexample.github.io
Examples for highlighting text of interest with various Linux CLI tools.| learnbyexample.github.io
Short, introductory guide for the Python programming language| learnbyexample.github.io
Awesome deals for programming books and courses during the 2024 festive season.| learnbyexample.github.io
Interactive TUI app with exercises and multiple-choice questions for beginner to intermediate level Python learners| learnbyexample.github.io
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).| learnbyexample
Concise learning resource for beginner to intermediate level Vim users| learnbyexample.github.io
Linux command line tools and Shell Scripting for beginner to intermediate level users.| learnbyexample.github.io
Interactive TUI app that gives a brief tour of the GNU awk command.| learnbyexample.github.io
Examples and resource links for the GNU datamash command.| learnbyexample.github.io
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.| learnbyexample
This book will teach you more than twenty specialized text processing tools provided by the GNU coreutils package.| learnbyexample.github.io
Combining motions such as w, % and f with editing commands like d, c and y require precise positioning to be effective.| learnbyexample
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.| learnbyexample
sed provides escape sequences to change the case of replacement strings, which might include backreferences, shell variables, etc.| learnbyexample
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.| learnbyexample
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.| learnbyexample
awk is handy to compare records and fields between two or more files. The key features used in the solution below:| learnbyexample
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:| learnbyexample
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.| learnbyexample
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.| learnbyexample
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:| learnbyexample
Quantifiers can be applied to literal characters, dot metacharacter, groups, backreferences and character classes.| learnbyexample
The grep command provides the -o option to extract only the matching portions. Here are some examples using the BRE/ERE regexp flavors:| learnbyexample
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:| learnbyexample
Moving within the visible window:| learnbyexample
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.| learnbyexample
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:| learnbyexample
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.| learnbyexample
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.| learnbyexample
Python provides a wide variety of features to work with strings. In this tip, you'll learn about string concatenation and repetition.| learnbyexample
You can execute external commands from within Vim. Here are some examples:| learnbyexample
You can use tac to reverse the input line wise. If you pass multiple input files, each file content will be reversed separately.| learnbyexample
When you use a for loop, you get one element per each iteration. If you need the index of the elements as well, use the enumerate() built-in function. You'll get a tuple value per each iteration, containing index (starting with 0 by default) and the value at that index.| learnbyexample
Here are some of the flags you can use with the substitute command:| learnbyexample
awk '!a[$0]++' is one of the most famous Awk one-liners. It eliminates line based duplicates while retaining input order. The following example shows it in action along with an illustration of how the logic works.| learnbyexample
Until Python 3.10, you had to use alternatives like the third-party regex module for possessive quantifiers and atomic grouping. The re module supports these features from Python 3.11 version.| learnbyexample
Until Python 3.10, you had to use alternatives like the third-party regex module for possessive quantifiers and atomic grouping. The re module supports these features from Python 3.11 version.| learnbyexample
Here are some commands you can use in Normal mode to move within the current file:| learnbyexample
The stat command is useful to get details like file type, size, inode, permissions, last accessed and modified timestamps, etc. You'll get all of these details by default. The -c and --printf options can be used to display only the required details in a particular format.| learnbyexample
The split() method splits a string based on the given substring and returns a list. By default, whitespace is used for splitting and empty elements are discarded.| learnbyexample
The syntax for g command (short for global) is shown below:| learnbyexample
The R command provided by GNU sed is very similar to r with respect to most of the rules seen in an earlier tip. But instead of reading entire file contents, R will read one line at a time from the source file when the given address matches. If entire file has already been read and another address matches, sed will proceed as if the line was empty.| learnbyexample
The insert() list method helps to insert an object before the given index. Negative indexing is also supported.| learnbyexample
Enable the globstar option to recursively match filenames within a specified path. You can use shopt -s globstar and shopt -u globstar to set and unset this option respectively.| learnbyexample
Definitions from :h word and :h WORD are quoted below to explain the difference between word and WORD.| learnbyexample
Many operations on container objects can be defined in terms of these three concepts. For example, if you want to sum the square of all even numbers:| learnbyexample
Multiple files can be opened in Vim within the same tab page and/or in different tabs. From :h windows-intro:| learnbyexample
While writing scripts, sometimes you just need to know if a file contains the pattern and act based on the exit status of the command. Instead of redirecting the output to /dev/null you can use the -q option. This will avoid printing anything on stdout and also provides speed benefit as processing would be stopped as soon as the given condition is satisfied.| learnbyexample
These commands allow you to move based on a single character search, within the current line only.| learnbyexample
You can use the -i option with GNU awk to load libraries. The inplace library comes by default with the GNU awk installation. Thus, you can use -i inplace to modify the original input itself. Make sure to test that the code is working as intended before using this option.| learnbyexample
You can use the sort() method for sorting lists inplace. The sorted() function can be used to get a sorted list from any iterable.| learnbyexample
Multiple files can be opened in Vim within the same tab page and/or in different tabs. From :h windows-intro:| learnbyexample
These two commands will help you convert tabs to spaces and vice versa. Both these commands support options to customize the width of tab stops and which occurrences should be converted.| learnbyexample
JSON (JavaScript Object Notation) is one of the ways you can store and retrieve data necessary for functioning of an application. For example, my projects Python regex exercises and Linux CLI text processing exercises need to load questions and save user progress. You might wonder why not just a plain text file? I needed dict in the code anyway and JSON offered seamless transition. Also, this arrangement avoided having to write extra code and test it for potential parsing issues.| learnbyexample
Here are Normal mode commands you can use to move within long lines that are spread over multiple screen lines:| learnbyexample
The Bash shell provides extglob option for advanced pattern matching of filenames. These will help you apply regexp like quantifiers, provide alternate patterns and negation. From man bash:| learnbyexample
Here are five string methods you can use for changing the case of characters. Word level transformation is determined by consecutive occurrences of alphabets, not limited to separation by whitespace characters.| learnbyexample
I've previously written about events and strategies that led to increased ebook sales during the last quarter of 2021.| learnbyexample
From :h options.txt:| learnbyexample
The r command accepts a filename as argument and when the address is satisfied, entire contents of the given file is added after the matching line. This is a robust way to add multiline text literally.| learnbyexample
The print() function can accept zero or more values separated by a comma. Here's how the function arguments are shown in help(print):| learnbyexample
Terminal mode is one way to use shell commands from within Vim.| learnbyexample
Consider these sample input files that are already sorted and the default output from comm:| learnbyexample
One of the ways to count the frequency of items is to make use of the dict.get() method:| learnbyexample
Here are some of the Normal mode commands for moving within the current line:| learnbyexample
GNU datamash has plenty of nifty features for field based operations. Here's an example of transposing comma delimited data:| learnbyexample
The pop() method removes the last element of a list by default. You can pass an index to delete that specific item and the list will be automatically re-arranged. Return value is the element being deleted.| learnbyexample
You can have multiple windows within the same tab page.| learnbyexample
You can use brace expansion for generating a sequence of numbers and alphabets. printf helps you to display multiple arguments using the same format specifier. For example:| learnbyexample
The str.translate() method accepts a table of codepoints (numerical value of a character) mapped to another character or codepoint. Map to None for characters that have to be deleted. You can use the ord() built-in function to get the codepoint of characters. Or, you can use the str.maketrans() method to generate the mapping for you.| learnbyexample
It is way too easy to repeat the last change you made:| learnbyexample
You can use mkdir -m instead of creating a directory with mkdir first and then changing the directory permissions with the chmod command. The argument to the -m (mode) option uses the same syntax as the chmod command.| learnbyexample
You can assign the individual elements of a sequence to multiple variables. This is known as sequence unpacking and it is handy in many situations.| learnbyexample
You can save and restore Vim sessions to continue working with the same setup before you had to quit Vim for reasons like switching off the machine, switching to another project, etc.| learnbyexample
Example based guide for text processing with Ruby from the command line.| learnbyexample.github.io
Learn Ruby Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises.| learnbyexample.github.io
Summary of ebooks and tools written, marketing efforts and misc items.| learnbyexample.github.io
Using ripgrep, perl, sd and GNU sed commands to perform multiline fixed string search and replace operations from the command line| learnbyexample.github.io
Awesome programming deals for books and courses during the festive season.| learnbyexample.github.io
Learn JavaScript Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises.| learnbyexample.github.io
Example based guide for text processing with Perl from the command line.| learnbyexample.github.io
Learn GNU awk with hundreds of examples and exercises.| learnbyexample.github.io
Interactive exercises to test your Linux CLI text processing skills for the GNU grep, sed and awk commands.| learnbyexample.github.io
Learn GNU sed with hundreds of examples and exercises.| learnbyexample.github.io
Learn GNU grep and ripgrep with hundreds of examples and exercises.| learnbyexample.github.io
Practice Python regular expressions interactively, includes both re and regex modules| learnbyexample.github.io
Playground for Python Regular Expressions, includes cheatsheet and interactive examples.| learnbyexample.github.io
Learn Python Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises.| learnbyexample.github.io
Quiz to stretch your understanding of Python regular expressions| learnbyexample.github.io
Summary of ebooks and tools written, marketing efforts and misc items.| learnbyexample.github.io
40 interactive exercises to test your Linux CLI text processing skills| learnbyexample.github.io