In this lab, You will gain practical knowledge in working with Regular Expressions and some command-based data processing tools like AWK. You will work on the given simple text file (data.txt) and use linux to process the file to answer some required queries.
- You must have linux or WSL to run the commands on the terminal
- Learn regular expression (Regex) and finish this tutorial here
- Gain lots of skills working with AWK from this article (until lession number 13 at least) here
- Try to work with AWK on this interactive tutorial here
1- Go to your working directory:
cd <your working dirctory Ex. 'cd C:\docker'>2- create a text file (data.txt for example) and insert the data we will work on:
nano data.txtThen paste the data instide this file and press "ctrl+o" then "enter" then "ctrl+x" to exit
3- To view the data:
cat data.txtNow you are ready to work on the quests ⚡✅
a- Print only the first and last names of all the clients (there must be a space between first and last names):
It can be done in two ways:
awk '{print $1, $2}' data.txtawk '{print $1 " " $2}' data.txtb- Same as above but print the names are in reverse order (last name, first name) and make sure there is a comma between last name and first name:
It can be done like this:
awk '{print $2 "," $1}' data.txtc- Print only first name and last name (without header that has the names of the columns: first name, last name, etc):
It can be done like this:
awk 'NR>1 {print $1, $2}' data.txtd- Same as above but with numbers indicating the client's order:
It can be done like this:
awk 'NR>1 {print NR-1, $1, $2}' data.txte- Print first and last names of customers who are more than 50 years old:
It can be done like this:
awk 'NR>1 && $4 > 50 {print $1, $2}' data.txtf- Print the first and last names of customers who own more than 10000$:
It can be done like this:
awk 'NR>1 && $5 > 10000 {print $1, $2}' data.txtg- Print the total sum of all money in all the accounts:
It can be done like this:
awk '{sum += $5} END {print sum}' data.txth- Print all the information of all accounts whose owner's first name is Chad. (hint. use REGEX):
It can be done like this:
awk '$1 ~ /^Chad$/ {print}' data.txti- Print all the information of all accounts whose owner's last name ends with the letter r (hint: REGEX):
It can be done like this:
awk 'NR>3 && $2 ~ /r$/ {print}' data.txtj- Print all the information of all accounts whose owner age has the number for the first and 2nd digits:
It can be done like this:
awk '$4 >= 10 && int($4/10) == $4 % 10 {print}' data.txtYou've completed this lab, I hope you find it helpful, follow me on my github profile to learn more exciting things ⚡💻










