Interactive exercises for GNU grep, sed and awk (TUI apps)
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.
You'll need Python for this (I used 3.8, it should work for more recent versions too). This app is available on PyPI as grepexercises, sedexercises and awkexercises. Example installation instructions are shown below, adjust them based on your preferences and OS.
# virtual environment
$ python3 -m venv textual_apps
$ cd textual_apps
$ source bin/activate
$ pip install grepexercises sedexercises awkexercises
# launch the app, example shown for the grep command
$ grepexercises
To run the app without having to enter the virtual environment again, add aliases to .bashrc
(or equivalent):
# you'll have to change the path
alias grepexercises='/path/to/textual_apps/bin/grepexercises'
# similarly, you can add aliases for the other apps as well
As an alternative to manually managing such virtual environments, you can use https://github.com/pypa/pipx instead:
$ pipx install grepexercises sedexercises awkexercises
$ awkexercises
As yet another alternative, you can install textual
(see Textual documentation for more details), clone my TUI-apps repository and run the Python file from respective folders. For example, grep_exercises.py
for the grep
command.
Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines).
You can use alternative CLI tools to solve these exercises as well. For example,
perl
instead ofGNU awk
orripgrep
instead ofGNU grep
and so on.
Brief Guide🔗
You can either click the buttons using mouse or press the key combinations listed below:
- Press F1 to view the complete guide from within the app itself.
- Press Ctrl+p and Ctrl+n to navigate the questions list.
- Type the command in the box below the question.
- Press Enter to execute the command.
- Output would be displayed below the command box.
- If the output matches the expected results, the command box will turn green and reference solutions will also be shown.
- Issues due to errors and timeout (about
2
seconds) will be displayed in red.
- Press Ctrl+s to view reference solutions anytime you want.
- Press Ctrl+t to toggle between light and dark themes.
- Press Ctrl+q to quit the app.
- Some basic readline-like shortcuts are supported, for example Ctrl+u, Ctrl+k, Ctrl+w, etc
Your progress is automatically saved when you close the app and restored when you launch it again later. Already answered questions will be skipped.
There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session.
Ebooks🔗
The exercise questions in these apps have been adapted from my programming ebooks: https://learnbyexample.github.io/books/
Feedback🔗
I'd highly appreciate your feedback. Please file an issue if there are bugs, crashes, etc.
Hope you find these TUI apps useful. Happy learning :)