Site icon

Embracing Linux in Windows 11: A Fun Journey with Regex and WSL

Introduction: Your Adventure Begins!

Welcome to an exciting fusion of Linux and Windows 11! Imagine you’re a digital explorer, ready to delve into the rich world of Linux, right from the comfort of your familiar Windows environment. This guide isn’t just about commands and codes; it’s about embarking on an adventure in data manipulation using the Windows Subsystem for Linux (WSL) and the art of regular expressions (regex). You’ll learn to harness the power of Linux’s command line, turning complex data tasks into simple, fun exercises.

Step 1: Unveiling the Linux Command Line in WSL

Imagine opening a treasure chest – that’s what it’s like when you first open WSL. Let’s peek inside:

ls # Reveals your treasures (files)

Accessing Windows Treasures from Linux:

cd /mnt/c # Enter the secret passage
ls # Behold the treasures (Windows files)

Step 2: The Essentials – Your Command Line Toolkit

Every explorer needs a toolkit. Here’s yours for navigating this new world:

Listing Files (ls):

ls
ls -l
ls -a

Changing Paths (cd):

cd Documents # Journey to Documents
cd .. # Step back

Identifying Your Location (pwd):

Never get lost! Use pwd to know exactly where you are.

pwd # Where am I?

Step 3: Fetching Precious Data from Distant Lands

Let’s embark on a quest to retrieve data from the mystical JSONPlaceholder API:

Using curl and wget:

wget -O posts.json https://jsonplaceholder.typicode.com/posts

Step 4: Mastering the Art of Regex – Your Secret Decoder

Regular expressions are like secret decoders for text. Crack codes and find patterns with ease!

Simple Regex Usage:

echo "Hello World 123" | grep -Eo '[A-Za-z]+' # Unearthing letters

Step 5: Filtering Data with Grep

Turn your data into a goldmine by extracting only the nuggets you need:

Using grep:

grep ‘”title”:’ posts.json # Discovering hidden titles

Step 6: Storing Your Loot – Redirecting Output

Now, let’s store these treasures in a new chest (a text file):

Saving Your Finds:

grep ‘”title”:’ posts.json > titles.txt # Locking away the titles
Step 7: Exploring and Altering Your Textual Treasures
Viewing and Editing:
Peek into your chest of texts and modify them as you wish.
cat titles.txt # Gaze upon your collection
nano titles.txt # Carve your marks (edit)
Bonus Knowledge: Extra Tools for Your Linux Adventure
Enhance your command line journey with these additional tools and knowledge:
Understanding Your Linux Environment:
Get to know your surroundings better with lsb_release -a.
lsb_release -a # Discover your Linux landscape

Author

Above guidelines on Getting started with Linux is contributed by our Premium kit community member Umang Gulati

Exit mobile version