pair_lister.sh
is a mini bash script that generates a list of command-comment pairs based on line numbers.
Generally, a cheat-sheet contains a set of notes for quick reference mostly consisting of command-comment pairs with some additional descriptions.
-
Sometimes you may prefer creating your own cheat-sheets while learning a specific technology from online sources such as PDFs, blogs or contents.
-
Catch is, the text becomes really messy when the markup data is copied from a browser page and pasted on a notepad. It requires a bit of text processing to make it look nice.
-
So, the challenge is to organize that unformatted data into command-comment pairs i.e. something visually pleasant.
Suppose, you're learning file expressions in Bash (courtesy of @bobbyiliev) and you have collected this data 👇
True if file exists.
[[ -a ${file} ]]
True if file exists and is a block special file.
[[ -b ${file} ]]
True if file exists and is a character special file.
[[ -c ${file} ]]
True if file exists and is a directory.
[[ -d ${file} ]]
Pair Lister turns it into following format 👇
[[ -a ${file} ]] # True if file exists.
[[ -b ${file} ]] # True if file exists and is a block special file.
[[ -c ${file} ]] # True if file exists and is a character special file.
[[ -d ${file} ]] # True if file exists and is a directory.
-
Download the script.
-
Set Variables
-
Place your raw data in a text file in the same directory and add its filename in the
DATA
variable. Ex:DATA="myfile.txt"
.⚠ Remember that the odd lines should contain comments and even lines contain corresponding commands
-
Alternatively, for a dry run, make sure the
DATA="samle_data.txt"
variable is unmodified.
-
-
Make the script executable.
$ chmod 755 pair_lister.sh
-
Run it.
$ ./pair_lister.sh
-
View formatted output
$ cat new_data.txt
👀 Feeling adventurous? You can get your desired output pattern by tweaking line 42 (printf) according to your need.