Video Coming Soon...
01: Gearing Up
In this exercise you'll either find or install the software you need to complete the course. You don't need much, just a Terminal, Text Editor, and two programs named grep
and sed
.
macOS/OSX
Terminal
- On macOS you'll need to access yourTerminal
program to run the exercises. You can findTerminal
in your Applications directory, or by hitting cmd-spacebar and typeing "terminal". Once it's running, right-click on it in your Dock and select "keep in dock" so that it's always there.- Text Editor - You need an editor that can work with only text. I recommend Geany as it's simple enough to use, but not so simple it's useless.
grep
- You should already have this on your computer. Open your terminal and typegrep -v
to run it.sed
- You should also have this too. In the same Terminal typesed -v
confirm it works.
You'll be using the command line (Terminal) in this course, but not very much. Most of the commands will be explained to you and demonstrated, but I may create a free command line crash course if enough people need it.
Linux
On Linux you should be able to follow the same setup as macOS. You'll need the following:
Terminal
- Some kind of terminal, which depends on the kind of Linux you have.- Geany - You may already have a text editor you like so just use that. If not, Geany should be available as a package and easy to install.
grep
- You can open your terminal and confirm you havegrep
withgrep -v
.sed
- Test that you havesed
in the same terminal window withsed -v
.
The version of sed
and grep
won't matter much since we'll be using only the most basic features.
Windows
For windows you have two choices:
- Use my automated install that will install many tools that I use in all of my courses.
- Manually install the software you need.
I'll cover the automatic process first since it'll install many useful things, but if you are paranoid about what is installed then just do it manually.
Automatic Windows Setup
WARNING It's better for you to create a special Administrator user, switch to that user, then remove admin privileges from your main user account. This will create a personal account and an admin account, which increases your security. Research has shown that running around the internet as Administrator is incredibly stupid. If you simply run as a regular user than you'll effectively stop about 80% of potential attack vectors, and it's not much of an inconvenience. Windows will prompt you for the admin user's password whenever you need admin rights.
Open a PowerShell (NOT PowerShell ISE) window and paste in these two commands one at a time:
irm https://learncodethehardway.com/setup/base.ps1 -outfile base.ps1
powershell -executionpolicy bypass .\base.ps1
Be sure that you stay at your keyboard and answer all the questions to install. Once these commands finish you can use winget
to install ugrep
and sed
:
winget install Genivia.ugrep
winget install mbuilov.sed
If everything worked then you should be able to start Terminal
by hitting the win
key and typing "terminal" into the start menu. You can also start Geany
the same way but type "geany."
After this you can test your installation by typing these two commands into Terminal
(which is just running PowerShell in a nicer window):
ugrep --version
sed --version
Keep in mind that you'll type the command ugrep
every time you see me type grep
, but it'll work the same after that.
Manual Windows Setup
This could also be called "The Minimalist Setup." You'll want to install the following:
- Windows Terminal -- This is the new Terminal from Microsoft. If you are running Windows 11 then you should already have this.
- Geany -- A decent programmer's text editor that is not too much, nor too little. Meaning it's not a full blown overcomplicated IDE, and it's not a basic text only editor.
- ugrep -- This is a great alternative to the usual grep that runs well on Windows.
- sed -- This is a decent build of GNU sed for Windows.
You can also install the tool winget and then install each of these quickly with these commands:
winget install Microsoft.WindowsTerminal
winget install Geany.Geany
winget install Genivia.ugrep
winget install mbuilov.sed
Once these are installed you're done. You can test your install by starting a new Terminal
and typing these two commands:
ugrep --version
sed --version
Also remember that when you I say you need to type grep
you should type ugrep
to run the version you installed.
Quick grep
Intro
Before we conclude this exercise I'll give you a quick introduction to running grep
(ugrep
on Windows). This will confirm that you're ready to continue with the rest of the exercises.
First the way to think about the command line is that you're talking to the computer inside the Terminal
. When you type a command, it is a sequence of words, each separated by spaces. When you typed grep --version
you were telling the Terminal (also called your "shell") to do this:
- Find the program named
grep
(ugrep
on Windows). - Run it but give it the extra argument
--version
. - Your OS (Windows, Linux, macOS) starts the program, and tells it the argument
--version
. - An "argument" is just an option, kind of like adding an adjective to a word like adding "big" to "cake." Or, like checking different checkboxes off in the options of a video game.
- The program runs, changes its behavior based on your argument, and in this case prints out its version information.
The most important thing to understand is that this will not work:
grep--version
If you're on windows then this will NOT work also:
ugrep--version
There needs to be a space between the word grep
and the argument --version
. Try typing this incorrect command so you can see what the error is.
Once you have a grasp on this, you can move on to the next exercise.
Further Study
- Type
grep --help
(ugrep --help
) to see the help options. These are probably way over your head, but it's always good to try things and see what you get. - Be careful with the commands
rm
anddel
. If you type them even slightly wrong you'll accidentally delete all your files. Just avoid them until you're more confident with your skills, and start making backups of your computer now just in case.
Register for Learn Regex the Hard Way
Register to gain access to additional videos which demonstrate each exercise. Videos are priced to cover the cost of hosting.