https://github.com/university-experience/regex-awk
Distributed Operation Systems Lab2
https://github.com/university-experience/regex-awk
awk docker linux regex regular-expression ubuntu
Last synced: about 1 month ago
JSON representation
Distributed Operation Systems Lab2
- Host: GitHub
- URL: https://github.com/university-experience/regex-awk
- Owner: University-Experience
- Created: 2024-03-18T14:33:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-18T15:01:20.000Z (about 1 year ago)
- Last Synced: 2025-01-24T16:49:45.842Z (3 months ago)
- Topics: awk, docker, linux, regex, regular-expression, ubuntu
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Regex-AWK Lab
## Introduction
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.## Lab requirements:
* 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# Steps to start:
1- Go to your working directory:
```bash
cd
```
2- create a text file (data.txt for example) and insert the data we will work on:
```bash
nano data.txt
```
Then paste the data instide this file and press "ctrl+o" then "enter" then "ctrl+x" to exit
3- To view the data:
```bash
cat data.txt
```
Now you are ready to work on the quests โกโ
## 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:```bash
awk '{print $1, $2}' data.txt
```
```bash
awk '{print $1 " " $2}' data.txt
```
b- 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:
```bash
awk '{print $2 "," $1}' data.txt
```
c- 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:
```bash
awk 'NR>1 {print $1, $2}' data.txt
```
d- Same as above but with numbers indicating the client's order:
It can be done like this:
```bash
awk 'NR>1 {print NR-1, $1, $2}' data.txt
```
e- Print first and last names of customers who are more than 50 years old:
It can be done like this:
```bash
awk 'NR>1 && $4 > 50 {print $1, $2}' data.txt
```
f- Print the first and last names of customers who own more than 10000$:
It can be done like this:
```bash
awk 'NR>1 && $5 > 10000 {print $1, $2}' data.txt
```
g- Print the total sum of all money in all the accounts:
It can be done like this:
```bash
awk '{sum += $5} END {print sum}' data.txt
```
h- Print all the information of all accounts whose owner's first name is Chad. (hint. use REGEX):
It can be done like this:
```bash
awk '$1 ~ /^Chad$/ {print}' data.txt
```
i- 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:
```bash
awk 'NR>3 && $2 ~ /r$/ {print}' data.txt
```
j- 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:
```bash
awk '$4 >= 10 && int($4/10) == $4 % 10 {print}' data.txt
```
## Congratulations ๐ฅณ๐ฅ
You've completed this lab, I hope you find it helpful, follow me on my github profile to learn more exciting things โก๐ป