├── .gitignore ├── BPT1_problem_1 ├── readme.md └── script.sh ├── BPT1_problem_2 ├── debug.md ├── readme.md └── solution.txt ├── BPT1_problem_3 ├── readme.md └── script.sh ├── BPT1_problem_4 ├── readme.md └── script.sh ├── BPT2_problem_1 ├── readme.md └── script.sh ├── BPT2_problem_2 ├── readme.md └── script.sh ├── BPT2_problem_3 ├── readme.md └── script.sh ├── BPT2_problem_4 ├── readme.md └── script.sh ├── BPT3_problem_1 ├── readme.md └── script.sh ├── BPT3_problem_2 ├── readme.md └── script.sh ├── BPT3_problem_3 ├── readme.md └── script.sh ├── BPT3_problem_4 ├── readme.md └── script.sh ├── BPT4_problem_1 ├── function.sh └── readme.md ├── BPT4_problem_2 ├── readme.md └── script.sh ├── BPT4_problem_3 ├── convert_file.sh └── readme.md ├── BPT4_problem_4 ├── readme.md └── replace_second_occurrence.sed ├── LICENSE ├── assignment_0 ├── readme.md └── script.sh ├── assignment_1 ├── readme.md └── script.sh ├── assignment_10 ├── readme.md └── script.sh ├── assignment_2 ├── readme.md └── script.sh ├── assignment_3 ├── fibonacci.bc └── readme.md ├── assignment_4 └── readme.md ├── assignment_5 └── readme.md ├── assignment_6 ├── html_output.html ├── readme.md └── script.sh ├── assignment_7 ├── api_output.json ├── readme.md └── script.sh ├── assignment_8 └── readme.md ├── assignment_9 └── readme.md ├── evaluate.sh ├── myCount.sh ├── oppe-practice-1 ├── readme.md └── script.sh ├── oppe-practice-10 └── readme.md ├── oppe-practice-11 └── readme.md ├── oppe-practice-12 └── readme.md ├── oppe-practice-2 └── readme.md ├── oppe-practice-3 └── readme.md ├── oppe-practice-4 └── readme.md ├── oppe-practice-5 └── readme.md ├── oppe-practice-6 └── readme.md ├── oppe-practice-7 └── readme.md ├── oppe-practice-8 └── readme.md ├── oppe-practice-9 └── readme.md ├── ppa_1.1 ├── movetext.sh └── readme.md ├── ppa_1.2 ├── filetypes.sh └── readme.md ├── ppa_2.1 ├── readme.md └── script.sh ├── ppa_2.2 ├── readme.md └── script.sh ├── ppa_3.1 ├── readme.md └── texts.sh ├── ppa_3.2 ├── calender.sh └── readme.md ├── ppa_3.3 ├── errorlog.sh └── readme.md ├── ppa_4.1 ├── dirs.sh └── readme.md ├── ppa_4.2 ├── Pincode_info.csv ├── pincode.sh └── readme.md ├── ppa_5.1 ├── oddargs.sh └── readme.md ├── ppa_5.2 ├── investment.sh └── readme.md ├── ppa_5.3 ├── long.sh └── readme.md ├── ppa_5.4 ├── arch.sh └── readme.md ├── ppa_5.5 ├── fail.sh └── readme.md ├── ppa_5.6 ├── login.sh └── readme.md ├── ppa_5.7 ├── logintime.sh └── readme.md ├── ppa_5.8 ├── readme.md └── su.sh ├── ppa_6.1 ├── readme.md └── swapcase.sh ├── ppa_6.2 ├── myCount.sh └── readme.md ├── ppa_6.3 ├── backup.sh └── readme.md ├── ppa_7.1 ├── evenodd.awk └── readme.md ├── ppa_7.2 ├── readme.md └── repeat.awk ├── ppa_7.3 ├── big.awk └── readme.md ├── practice_2.1 ├── readme.md └── solution.md ├── practice_2.2 ├── readme.md └── script.sh ├── practice_2.3 ├── readme.md └── script.sh ├── practice_3.1 ├── readme.md └── solution.md ├── practice_3.2 ├── readme.md └── script.sh ├── practice_4.1 ├── readme.md └── script.sh ├── practice_4.10 ├── readme.md └── script.sh ├── practice_4.2 ├── readme.md └── script.sh ├── practice_4.3 ├── readme.md └── script.sh ├── practice_4.4 ├── readme.md └── script.sh ├── practice_4.5 ├── readme.md └── script.sh ├── practice_4.6 ├── readme.md └── script.sh ├── practice_4.7 ├── readme.md └── script.sh ├── practice_4.8 ├── readme.md └── script.sh ├── practice_4.9 ├── readme.md └── script.sh ├── practice_5.1 ├── readme.md └── solution.md ├── practice_5.10 ├── readme.md └── script.sh ├── practice_5.11 ├── readme.md └── script.sh ├── practice_5.12 ├── readme.md └── script.sh ├── practice_5.2 ├── readme.md └── solution.md ├── practice_5.3 ├── readme.md └── solution.md ├── practice_5.4 ├── readme.md └── script.sh ├── practice_5.5 ├── readme.md └── script.sh ├── practice_5.6 ├── readme.md └── script.sh ├── practice_5.7 ├── readme.md └── script.sh ├── practice_5.8 ├── readme.md └── script.sh ├── practice_5.9 ├── readme.md └── script.sh ├── practice_7.1a ├── readme.md └── script.sh ├── practice_7.1b ├── readme.md └── script.sh ├── practice_7.1c ├── readme.md └── script.sh ├── practice_7.2 ├── readme.md └── script.sh ├── practice_7.3 ├── readme.md └── script.sh ├── practice_7.4 ├── readme.md └── script.sh ├── practice_7.5 ├── readme.md └── script.sh ├── practice_7.6 ├── readme.md └── script.sh ├── practice_7.7 ├── readme.md └── script.sh ├── practice_7.8 ├── readme.md └── script.sh ├── practice_7.9 ├── readme.md └── script.sh ├── practice_8.1 ├── readme.md └── script.sh ├── practice_8.2 ├── readme.md └── script.sh ├── practice_8.3 ├── readme.md └── script.sh ├── practice_8.4 ├── readme.md └── script.sed ├── practice_8.5 ├── OPTS ├── readme.md └── script.sed ├── practice_9.1 ├── file.awk └── readme.md ├── practice_9.2 ├── file.awk └── readme.md ├── practice_9.3 ├── readme.md └── union.awk ├── practice_9.4 ├── readme.md └── script.awk ├── practice_9.5 ├── readme.md └── script.awk ├── q-awk-1 ├── readme.md └── script.sh ├── q-awk-2 ├── readme.md └── script.sh ├── q-awk-3 ├── readme.md └── script.sh ├── q-awk-4 ├── readme.md └── script.sh ├── q-awk-5 ├── readme.md └── script.sh ├── q-bash-1 ├── readme.md └── script.sh ├── q-bash-2 ├── readme.md └── script.sh ├── q-bash-3 ├── readme.md └── script.sh ├── q-bash-4 ├── readme.md └── script.sh ├── q-grep-1 ├── readme.md └── script.sh ├── q-grep-2 ├── readme.md └── script.sh ├── q-grep-3 ├── readme.md └── script.sh ├── q-grep-4 ├── readme.md └── script.sh ├── q-grep-5 ├── readme.md └── script.sh ├── q-sed-1 ├── readme.md └── script.sed ├── q-sed-2 ├── readme.md └── script.sed ├── q-sed-3 ├── readme.md └── script.sed ├── q-sed-4 ├── readme.md └── script.sed ├── q-sed-5 ├── readme.md └── script.sed ├── readme.md └── regex.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /BPT1_problem_1/readme.md: -------------------------------------------------------------------------------- 1 | A company has 5 departments, each named `Dept1` to `Dept5`. Within each department, there are 3 teams labeled `TeamA` to `TeamC`. Each team works on 10 projects. 2 | 3 | There is a directory for every team in `~/se2001/BPT1_problem_1/`. 4 | 5 | **Write Bash command(s) to create a file for each project, with the files named from `project1` to `project10`, in every team directory. Each file should be empty to ensure minimal space usage.** 6 | 7 | **Note** Please run synchro init command before you start working on your solution. -------------------------------------------------------------------------------- /BPT1_problem_1/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for dept in Dept{1..5}; do 4 | for team in Team{A..C}; do 5 | for project in {1..10}; do 6 | touch "./$dept/$team/project$project" 7 | done 8 | done 9 | done 10 | -------------------------------------------------------------------------------- /BPT1_problem_2/debug.md: -------------------------------------------------------------------------------- 1 | # Debugging Tips 2 | 3 | ## Important Note 4 | If you encounter test failures related to links, please ensure you are using **absolute paths** instead of **relative paths**. This can help avoid issues with link resolution during testing. 5 | -------------------------------------------------------------------------------- /BPT1_problem_2/readme.md: -------------------------------------------------------------------------------- 1 | Please use your knowledge of the commands like `mkdir`, `touch`, `ln` etc. to achieve the following directory structure in the current working directory by running the commands (not a script). 2 | 3 | 1. **Create Directories**: 4 | 5 | - Create a base directory called `project`. 6 | - Within `project`, create the following subdirectories using brace expansion: 7 | - `src/{module1,module2}/{include,lib}` 8 | - `docs/{api,manual}` 9 | - Create a directory `bin` within `project`. 10 | 11 | 12 | 2. **Create Files**: 13 | 14 | - Inside `src/module1/include`, create an empty file named `module1.h`. 15 | - Inside `src/module1/lib`, create an empty file named `module1.so`. 16 | - Inside `src/module2/include`, create an empty file named `module2.h`. 17 | - Inside `src/module2/lib`, create an empty file named `module2.so`. 18 | 19 | 20 | 3. **Create Hard Links**: 21 | 22 | - Create a hard link to `module1.h` in the `bin` directory and name it `module1_hardlink.h`. 23 | - Create a hard link to `module2.so` in the `bin` directory and name it `module2_hardlink.so`. 24 | 25 | 26 | 4. **Create Soft Links**: 27 | 28 | - Create a soft link to the `docs` directory in the `project` directory and name it `documentation`. 29 | - Create a soft link to `module1.so` inside `module2/lib` directory and name it `module1_symlink.so`. 30 | 31 | 32 | 5. **Modify Permissions**: 33 | 34 | - Set the permission of `project` directory to `755`. 35 | - Set the permission of all directories under `project/src` to `700`. 36 | - Set the permission of all `.h` files to `644`. 37 | - Set the permission of all `.so` files to `755`. -------------------------------------------------------------------------------- /BPT1_problem_2/solution.txt: -------------------------------------------------------------------------------- 1 | mkdir -p project/src/{module1,module2}/{include,lib} project/docs/{api,manual} project/bin 2 | 3 | touch project/src/module1/include/module1.h project/src/module1/lib/module1.so 4 | touch project/src/module2/include/module2.h project/src/module2/lib/module2.so 5 | 6 | ln project/src/module1/include/module1.h project/bin/module1_hardlink.h 7 | ln project/src/module2/lib/module2.so project/bin/module2_hardlink.so 8 | 9 | ln -s project/docs project/documentation 10 | ln -s project/src/module1/lib/module1.so project/src/module2/lib/module1_symlink.so 11 | 12 | chmod 755 project 13 | chmod 700 project/src/module1/include project/src/module1/lib project/src/module2/include project/src/module2/lib 14 | chmod 644 project/src/module1/include/module1.h project/src/module2/include/module2.h 15 | chmod 755 project/src/module1/lib/module1.so project/src/module2/lib/module2.so 16 | 17 | -------------------------------------------------------------------------------- /BPT1_problem_3/readme.md: -------------------------------------------------------------------------------- 1 | You are given two text files, `file1.txt` and `file2.txt` in the `/opt/assets/` directory, each containing a list of names of world rivers (one name per line) in current working directory. Write two sequential commands in a file `script.sh` and make it executable such that the script will do the following 2 | 3 | 1. Display the differences between them in a unified format. 4 | 5 | 2. Print the names that are common to both files. 6 | 7 | **Hint** 8 | 9 | - **Use appropriate flags/options present in the following commands. Please use man pages or --help flag to understand what each flag do.** 10 | 11 | - **Use `diff`**: Compare the two files and display the differences between them in a unified format. 12 | 13 | - **Use** `comm`: can be used for the following 14 | - Names that are common to both files. -------------------------------------------------------------------------------- /BPT1_problem_3/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | diff -u /opt/assets/file1.txt /opt/assets/file2.txt 4 | comm -12 <(sort /opt/assets/file1.txt) <(sort /opt/assets/file2.txt) -------------------------------------------------------------------------------- /BPT1_problem_4/readme.md: -------------------------------------------------------------------------------- 1 | Please use the nslookup command (on powershell or linux on your local system) to identify the IP addresses associated with the following websites. After obtaining the IP addresses, enter each one into a browser to check if it directs you to the corresponding website. For each website, print the result using the echo command: if the website is successfully reached using the IP address, print "www.website.com Yes", otherwise print "www.website.com No". Perform these steps for each website sequentially: 2 | 3 | www.google.com 4 | www.yahoo.com 5 | www.duckduckgo.com 6 | www.youtube.com 7 | www.aws.amazon.com 8 | 9 | Create a file with name `script.sh` which contains the `echo` commands sequentially. 10 | 11 | Hint: 12 | 13 | You can use the nslookup command for DNS lookup. 14 | 15 | What is DNS and Why Perform a DNS Lookup?: The Domain Name System (DNS) translates human-readable domain names (like www.example.com) into IP addresses (like 93.184.216.34). DNS is crucial because it allows users to access websites using domain names instead of remembering complex IP addresses. A DNS lookup retrieves the IP address associated with a domain name, which is essential for network troubleshooting and ensuring that domain names are correctly mapped to their respective IP addresses. -------------------------------------------------------------------------------- /BPT1_problem_4/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "www.google.com Yes" 3 | echo "www.yahoo.com No" 4 | echo "www.duckduckgo.com Yes" 5 | echo "www.youtube.com No" 6 | echo "www.aws.amazon.com No" -------------------------------------------------------------------------------- /BPT2_problem_1/readme.md: -------------------------------------------------------------------------------- 1 | Write a **bash script** `script.sh` to extract the country name and its capital from a HTML file. 2 | Assume that the HTML Code is of the following format and convert it in to the format as shown in the sample output. 3 | 4 | **Note** 5 | 6 | The HTML input to the script will be sent through standard input. 7 | 8 | **Sample Input** 9 | 10 | ```html 11 |
Date | 13 |Temp (°C) | 14 |Description | 15 |
27 Mar (Mon) | 18 |15°C | 34°C | 19 |Clear | 20 |
28 Mar (Tue) | 23 |16°C | 34°C | 24 |Clear | 25 |
29 Mar (Wed) | 28 |16°C | 35°C | 29 |Clear | 30 |
30 Mar (Thu) | 33 |17°C | 34°C | 34 |Partly Cloudy | 35 |
31 Mar (Fri) | 38 |18°C | 34°C | 39 |Partly Cloudy | 40 |
1 Apr (Sat) | 43 |18°C | 34°C | 44 |Partly Cloudy | 45 |
script.sh
.
--------------------------------------------------------------------------------
/practice_7.1a/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | read -p num1
4 | read -p num2
5 |
6 | sum=$((num1 + num2))
7 | echo $sum
--------------------------------------------------------------------------------
/practice_7.1b/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 1b
2 |
3 | Write a Bash script that accepts a name (string) as command line argument to your script script.sh
and print "hello input-name
" as output, where input-name
is the input string.
4 |
5 | Example:
6 |
7 | If the command line input string is Raghu
the output should be
8 | hello Raghu
9 |
10 | Write your script in the file script.sh
.
--------------------------------------------------------------------------------
/practice_7.1b/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "hello $1"
--------------------------------------------------------------------------------
/practice_7.1c/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 1c
2 |
3 | Write a bash script that reads two numbers from the standard input and prints the sum of the numbers. Assume that the input will be numeric only.
4 |
5 | Write your script in the file script.sh
.
--------------------------------------------------------------------------------
/practice_7.1c/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | read num1
4 | read num2
5 |
6 | sum=$((num1 + num2))
7 | echo $sum
--------------------------------------------------------------------------------
/practice_7.2/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 2
2 |
3 | Write a bash script named ` script.sh ` that takes two arguments, checks if both the arguments are positive integers then prints their sum; else prints "NOT INTEGERS" to STDERR and exits with exit code 1.
4 |
5 | Note: Use the below if else conditional statement if needed.
6 |
7 | ```bash
8 | if condition; then
9 | ...
10 | ...
11 | else
12 | ...
13 | ...
14 | fi
15 | ```
--------------------------------------------------------------------------------
/practice_7.2/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [[ $1 =~ ^[0-9]+$ ]] && [[ $2 =~ ^[0-9]+$ ]]; then
4 | echo $(($1 + $2))
5 | else
6 | echo "NOT INTEGERS" >&2
7 | exit 1
8 | fi
--------------------------------------------------------------------------------
/practice_7.3/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 3
2 |
3 | Write a bash script named ` script.sh `. The script takes two arguments, checks if both the arguments are positive integers then prints their sum; else concatenate the string values in both the arguments and prints the combined string.
--------------------------------------------------------------------------------
/practice_7.3/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [[ $1 =~ ^[0-9]+$ ]] && [[ $2 =~ ^[0-9]+$ ]]; then
4 | echo $(($1 + $2))
5 | else
6 | echo "$1$2"
7 | fi
--------------------------------------------------------------------------------
/practice_7.4/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 4
2 |
3 | Write a bash script named ` script.sh ` that accepts a file path as an argument and checks if that exists and is readable by the current user and prints the output as below.
4 |
5 | - Prints "DOES NOT EXIST" on STDERR and return with error code 1 if the file does not exist at the given path.
6 | - Prints "NOT READABLE" on STDERR and return with error code 2 if the file is not readable by the current user.
7 | - Prints "WOO HOO" if the file exists and is readable too.
8 |
9 | Note:
10 | - Use the below if elif conditional statement if needed
11 |
12 | ```bash
13 | if condition; then
14 | ...
15 | ...
16 | elif condition; then
17 | ...
18 | ...
19 | else
20 | ...
21 | ...
22 | fi
23 | ```
24 |
25 | - The files will be created during ` synchro eval `.
--------------------------------------------------------------------------------
/practice_7.4/script.sh:
--------------------------------------------------------------------------------
1 | if [ -e $1 ]; then
2 | if [ -r $1 ]; then
3 | echo "WOO HOO"
4 | else
5 | echo "NOT READABLE" >&2
6 | exit 2
7 | fi
8 | else
9 | echo "DOES NOT EXIST" >&2
10 | exit 1
11 | fi
--------------------------------------------------------------------------------
/practice_7.5/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 5
2 |
3 | Write a bash script in ` script.sh ` file that takes an argument which takes a positive integer as argument and prints it in reverse order (For example, if the input number is 123, the Output will be 321)
--------------------------------------------------------------------------------
/practice_7.5/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo $1 | rev
--------------------------------------------------------------------------------
/practice_7.6/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 6
2 |
3 | Write a bash script in the file ` script.sh ` that accepts an integer argument say ` n ` and prints the below pattern for ` n ` lines.
4 |
5 | For example,
6 | In the below sample, the value of `n` is 5
7 | ```
8 | *
9 | **
10 | ***
11 | ****
12 | *****
13 | ```
14 |
15 | In the below sample, the value of `n` is 4.
16 |
17 | ```
18 | *
19 | **
20 | ***
21 | ****
22 | ```
--------------------------------------------------------------------------------
/practice_7.6/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | for i in $(seq 1 $1); do
4 | printf '%*s\n' "$i" | tr " " "*"
5 | done
--------------------------------------------------------------------------------
/practice_7.7/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 7
2 |
3 | Write a bash script in ` script.sh ` file that takes an integer argument and prints whether the number is prime or not. If the number in the argument is a prime number, the program must print "Prime" and if not, it must print "Not Prime"s
--------------------------------------------------------------------------------
/practice_7.7/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | num=$1
4 | is_prime=1
5 |
6 | if [ $num -lt 2 ]; then
7 | is_prime=0
8 | fi
9 |
10 | for (( i=2; i*i<=$num; i++ )); do
11 | if [ $((num % i)) -eq 0 ]; then
12 | is_prime=0
13 | break
14 | fi
15 | done
16 |
17 | if [ $is_prime -eq 1 ]; then
18 | echo "Prime"
19 | else
20 | echo "Not Prime"
21 | fi
--------------------------------------------------------------------------------
/practice_7.8/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 8
2 |
3 | ` df -h ` gives the disk/filesystem usage information. Write a bash script to list all the filesystem mount point names based on their percentage usage divided in 5 categories in the format below.
4 |
5 | ```pseudo
6 | 0-50
7 | (names of filesystem one in each line with usage between 0 to 50%)
8 | 50-75
9 | (names of filesystem one in each line with usage between 50 to 75%)
10 | 75-85
11 | (names of filesystem one in each line with usage between 75 to 85%)
12 | 85-95
13 | (names of filesystem one in each line with usage between 85 to 95%)
14 | >95
15 | (names of filesystem one in each line with usage above 95%)
16 | ```
17 |
18 | In each category, print the range in one line, followed by the filesystem mount point names. Print the range string even if there are no filesystems with usage in that range. Your script should not print anything else, all other errors and output from your script should be redirected to /dev/null.
19 |
20 | Write your script in file ` script.sh `.
21 |
22 | Filesystem mount point name is the last field in the output of df -h.
23 |
24 | The categories are
25 |
26 | - 0% to less than 50% usage.
27 | - 50% to less than 75% usage.
28 | - 75% to less than 85% usage.
29 | - 85% to less than 95% usage.
30 | - Equal and above 95% usage.
31 |
32 | Hint: Can store the df command output in a file. Then work on the file named ` dfOutput.txt ` line by line using the below script.
33 |
34 | ```Bash
35 | while read -r line;
36 | do
37 | echo $line; # To print the line.
38 | # Write your code to process the line.
39 | done < dfOutput.txt
40 | ```
41 |
42 | Use ${var:0:-1} to remove the last character of string var.
43 |
44 | Note:
45 | - The file ` dfOutput.txt ` will be made available during evaluation.
--------------------------------------------------------------------------------
/practice_7.8/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | exec 2>/dev/null
4 |
5 | categories=("0-50" "50-75" "75-85" "85-95" ">95")
6 | ranges=(50 75 85 95)
7 |
8 | declare -A filesystems
9 | for category in "${categories[@]}"; do
10 | filesystems["$category"]=""
11 | done
12 |
13 | while read -r line; do
14 | [[ "$line" =~ ^Filesystem ]] && continue
15 | [[ -z "$line" ]] && continue
16 |
17 | usage=$(echo "$line" | awk '{print $5}' | tr -d '%')
18 | mount_point=$(echo "$line" | awk '{$1=$2=$3=$4=$5=""; print substr($0,6)}' | sed 's/^[[:space:]]*//')
19 |
20 | if ! [[ "$usage" =~ ^[0-9]+$ ]] || [[ -z "$mount_point" ]]; then
21 | continue
22 | fi
23 |
24 | if (( usage < ranges[0] )); then
25 | filesystems["0-50"]+="$mount_point"$'\n'
26 | elif (( usage < ranges[1] )); then
27 | filesystems["50-75"]+="$mount_point"$'\n'
28 | elif (( usage < ranges[2] )); then
29 | filesystems["75-85"]+="$mount_point"$'\n'
30 | elif (( usage < ranges[3] )); then
31 | filesystems["85-95"]+="$mount_point"$'\n'
32 | else
33 | filesystems[">95"]+="$mount_point"$'\n'
34 | fi
35 | done < dfOutput.txt
36 |
37 | for category in "${categories[@]}"; do
38 | echo "$category"
39 | if [[ -n "${filesystems[$category]}" ]]; then
40 | echo -e -n "${filesystems[$category]}" | sed '/^$/d'
41 | fi
42 | done
43 |
--------------------------------------------------------------------------------
/practice_7.9/readme.md:
--------------------------------------------------------------------------------
1 | # Week 7 Problem 9
2 |
3 | In Problem 8, modify the output of your script as below.
4 |
5 | - Print the range string only if there is a filesystem in that range.
6 |
7 | For example, if there is no filesystem with usage >95% and also none in the range 75-85, and the rest all range has at least one filesystem with usage in that range than your output should be
8 |
9 | ```pseudo
10 | 0-50
11 | (names of filesystem one in each line with usage between 0 to 50%)
12 | 50-75
13 | (names of filesystem one in each line with usage between 50 to 75%)
14 | 85-95
15 | (names of filesystem one in each line with usage between 85 to 95%)
16 | ```
17 |
18 | Note:
19 | - ` dfOutput.txt ` will be made available during evaluation.
--------------------------------------------------------------------------------
/practice_7.9/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | exec 2>/dev/null
4 |
5 | categories=("0-50" "50-75" "75-85" "85-95" ">95")
6 | ranges=(50 75 85 95)
7 |
8 | declare -A filesystems
9 | for category in "${categories[@]}"; do
10 | filesystems["$category"]=""
11 | done
12 |
13 | while read -r line; do
14 | [[ "$line" =~ ^Filesystem ]] && continue
15 | [[ -z "$line" ]] && continue
16 |
17 | usage=$(echo "$line" | awk '{print $5}' | tr -d '%')
18 | mount_point=$(echo "$line" | awk '{$1=$2=$3=$4=$5=""; print substr($0,6)}' | sed 's/^[[:space:]]*//')
19 |
20 | if ! [[ "$usage" =~ ^[0-9]+$ ]] || [[ -z "$mount_point" ]]; then
21 | continue
22 | fi
23 |
24 | if (( usage < ranges[0] )); then
25 | filesystems["0-50"]+="$mount_point"$'\n'
26 | elif (( usage < ranges[1] )); then
27 | filesystems["50-75"]+="$mount_point"$'\n'
28 | elif (( usage < ranges[2] )); then
29 | filesystems["75-85"]+="$mount_point"$'\n'
30 | elif (( usage < ranges[3] )); then
31 | filesystems["85-95"]+="$mount_point"$'\n'
32 | else
33 | filesystems[">95"]+="$mount_point"$'\n'
34 | fi
35 | done < dfOutput.txt
36 |
37 | for category in "${categories[@]}"; do
38 | if [[ -n "${filesystems[$category]}" ]]; then
39 | echo "$category"
40 | echo -e -n "${filesystems[$category]}" | sed '/^$/d'
41 | fi
42 | done
43 |
--------------------------------------------------------------------------------
/practice_8.1/readme.md:
--------------------------------------------------------------------------------
1 | # Week 8 Problem 1
2 |
3 | A software company has published some best practices for writing the code. One of the best practices mentioned is that no line in your code should exceed 50 characters in total including all types of characters or spaces.
4 |
5 | Write a bash script ` script.sh ` using sed that prints the names of all .c files that contain one or more lines with a length of more than 50 characters (as specified above).
6 |
7 | Hint:
8 |
9 | q [exit-code]
10 | Immediately quit the sed script without processing any more
11 | input, except that if auto-print is not disabled the cur‐
12 | rent pattern space will be printed. The exit code argument
13 | is a GNU extension.
14 |
15 | Q [exit-code]
16 | Immediately quit the sed script without processing any more
17 | input. This is a GNU extension.
18 |
19 | Note:
20 | - The files will be made available during evaluation.
21 |
--------------------------------------------------------------------------------
/practice_8.1/script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | grep -l '.\{51\}' *.c | sort
4 |
--------------------------------------------------------------------------------
/practice_8.2/readme.md:
--------------------------------------------------------------------------------
1 | # Week 8 Problem 2
2 |
3 | Write a bash script ` script.sh ` using sed to print the contents of file ` $filename ` in the format ` sed is a steam editor known for manipulation of text.
19 | sed can manipulate the text in the pipeline and can be used alond with other commands as well
-n, --quiet, --silent | 24 |suppress automatic printing of pattern space | 25 |
-e script, --expression=script | 28 |add the script to the commands to be executed | 29 |
-f script-file, --file=script-file | 32 |add the contents of script-file to the commands to be executed | 33 |
-i[SUFFIX], --in-place[=SUFFIX] | 36 |edit files in place (makes backup if SUFFIX supplied) | 37 |
-l N, --line-length=N | 40 |specify the desired line-wrap length for the `l' command | 41 |
-E, -r, --regexp-extended | 44 |use extended regular expressions in the script (for portability use POSIX -E). | 45 |