From a7e135ffe144c2801f9906aebcae2be22b390c9d Mon Sep 17 00:00:00 2001 From: kirill1261 <174480879+kirill1261@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:46:28 +0300 Subject: [PATCH 01/31] strlen --- courses/cunix/ex01/src/strlen.c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 courses/cunix/ex01/src/strlen.c diff --git a/courses/cunix/ex01/src/strlen.c b/courses/cunix/ex01/src/strlen.c new file mode 100644 index 00000000..19b1e2b1 --- /dev/null +++ b/courses/cunix/ex01/src/strlen.c @@ -0,0 +1,11 @@ +#include + +size_t my_strlen(const char *str); + +int main() { + const char *test_str = "Hello, World!"; + size_t length = my_strlen(test_str); + + printf("Length of '%s' is %zu\n", test_str, length); + return 0; +} \ No newline at end of file From 7f550d3f1d480eecf930748f182a90fddae27fdf Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 24 Jul 2024 19:13:17 +0300 Subject: [PATCH 02/31] Update strlen.c --- courses/cunix/ex01/src/strlen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/courses/cunix/ex01/src/strlen.c b/courses/cunix/ex01/src/strlen.c index 19b1e2b1..10aca0d6 100644 --- a/courses/cunix/ex01/src/strlen.c +++ b/courses/cunix/ex01/src/strlen.c @@ -6,6 +6,6 @@ int main() { const char *test_str = "Hello, World!"; size_t length = my_strlen(test_str); - printf("Length of '%s' is %zu\n", test_str, length); + printf( test_str, length); return 0; -} \ No newline at end of file +} From d9e1a20b663827310a5450a3631b385342aa0038 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 24 Jul 2024 19:20:34 +0300 Subject: [PATCH 03/31] Update strlen.c --- courses/cunix/ex01/src/strlen.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/courses/cunix/ex01/src/strlen.c b/courses/cunix/ex01/src/strlen.c index 10aca0d6..34fde5ef 100644 --- a/courses/cunix/ex01/src/strlen.c +++ b/courses/cunix/ex01/src/strlen.c @@ -1,11 +1,11 @@ #include - -size_t my_strlen(const char *str); +#include "my_strlen.h" int main() { const char *test_str = "Hello, World!"; - size_t length = my_strlen(test_str); - - printf( test_str, length); + int length = my_strlen(test_str); + + printf("Length of the string is: %d\n", length); + return 0; } From 1fcc9f848eb974f299b111e988cc2d31429eaade Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:44:07 +0300 Subject: [PATCH 04/31] Update ex02 --- courses/bash/ex02/kirill | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 courses/bash/ex02/kirill diff --git a/courses/bash/ex02/kirill b/courses/bash/ex02/kirill new file mode 100644 index 00000000..023ec6c6 --- /dev/null +++ b/courses/bash/ex02/kirill @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 'pattern'" + exit 1 +fi + +pattern=$1 + +find . -type d | while read -r dir; do + # Get the relative path + rel_path=${dir#./} + + if echo "$rel_path" | grep -w -q "$pattern"; then + echo "$rel_path" + fi +done \ No newline at end of file From cd15fb029b1c72bd8284b4387ed48c1b658fe48d Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:46:17 +0300 Subject: [PATCH 05/31] Update ex03 --- courses/bash/ex03/kirill | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 courses/bash/ex03/kirill diff --git a/courses/bash/ex03/kirill b/courses/bash/ex03/kirill new file mode 100644 index 00000000..53b61c37 --- /dev/null +++ b/courses/bash/ex03/kirill @@ -0,0 +1,31 @@ +ех3 #!/bin/bash + +if [ "$#" -ne 4 ]; then + echo "Usage: $0 filename keyword1 keyword2 keyword3" >&2 + exit 1 +fi + +filename=$1 +keyword1=$2 +keyword2=$3 +keyword3=$4 + +if [ ! -r "$filename" ]; then + exit 1 +fi + +search_keyword() { + local keyword=$1 + local matches + matches=$(grep -c "$keyword" "$filename") + echo "Keyword: $keyword" + echo "Number of matches: $matches" + grep "$keyword" "$filename" + echo "" +} + +search_keyword "$keyword1" +search_keyword "$keyword2" +search_keyword "$keyword3" + +exit 0 \ No newline at end of file From 1e3c238d2be093b36e0e895f8b0d83dd2622db2a Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:47:13 +0300 Subject: [PATCH 06/31] Update kirill --- courses/bash/ex03/kirill | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/courses/bash/ex03/kirill b/courses/bash/ex03/kirill index 53b61c37..cb4125cb 100644 --- a/courses/bash/ex03/kirill +++ b/courses/bash/ex03/kirill @@ -1,4 +1,4 @@ -ех3 #!/bin/bash + #!/bin/bash if [ "$#" -ne 4 ]; then echo "Usage: $0 filename keyword1 keyword2 keyword3" >&2 From a734094677eb52b2f70fa5f2e0556623956b70ee Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:48:04 +0300 Subject: [PATCH 07/31] Update ex04 --- courses/bash/ex04/kirill | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 courses/bash/ex04/kirill diff --git a/courses/bash/ex04/kirill b/courses/bash/ex04/kirill new file mode 100644 index 00000000..52347d65 --- /dev/null +++ b/courses/bash/ex04/kirill @@ -0,0 +1,17 @@ +#!/bin/bash + +# Check if the correct number of arguments is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 pattern" >&2 + exit 1 +fi + +pattern=$1 + +# Use find to search for all files in or below the current working directory +find . -type f | while read -r file; do + # Use grep to search for the pattern in each file and print file path and line number + grep -Hn "$pattern" "$file" +done + +exit 0 \ No newline at end of file From 9dba5ab64eebebdbac66357ee671747c8f4938db Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:49:08 +0300 Subject: [PATCH 08/31] Update kirill --- courses/bash/ex04/kirill | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/courses/bash/ex04/kirill b/courses/bash/ex04/kirill index 52347d65..317e7c2c 100644 --- a/courses/bash/ex04/kirill +++ b/courses/bash/ex04/kirill @@ -1,6 +1,5 @@ #!/bin/bash -# Check if the correct number of arguments is provided if [ "$#" -ne 1 ]; then echo "Usage: $0 pattern" >&2 exit 1 @@ -8,9 +7,8 @@ fi pattern=$1 -# Use find to search for all files in or below the current working directory find . -type f | while read -r file; do - # Use grep to search for the pattern in each file and print file path and line number + grep -Hn "$pattern" "$file" done From 47be7b33febd3ef78eba205c0aaceb5f3ef0af0e Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:49:57 +0300 Subject: [PATCH 09/31] Update ex05 --- courses/bash/ex05/kirill | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 courses/bash/ex05/kirill diff --git a/courses/bash/ex05/kirill b/courses/bash/ex05/kirill new file mode 100644 index 00000000..77e9e1e2 --- /dev/null +++ b/courses/bash/ex05/kirill @@ -0,0 +1,55 @@ + #!/bin/bash + +# Check if at least one argument is provided +if [ "$#" -lt 2 ]; then + echo "Usage: $0 {-m|-s|-e|-o} number1 number2 ..." >&2 + exit 1 +fi + +# Get the operation argument +operation=$1 +shift + +# Initialize variables +sum=0 +count=0 +even_sum=0 +odd_sum=0 + +# Loop through all the numbers provided +for number in "$@"; do + sum=$(echo "$sum + $number" | bc) + count=$((count + 1)) + if [ $((number % 2)) -eq 0 ]; then + even_sum=$(echo "$even_sum + $number" | bc) + else + odd_sum=$(echo "$odd_sum + $number" | bc) + fi +done + +# Perform the required operation +case $operation in + -s) + echo "Sum: $sum" + ;; + -e) + echo "Sum of even numbers: $even_sum" + ;; + -o) + echo "Sum of odd numbers: $odd_sum" + ;; + -m) + if [ $count -ne 0 ]; then + mean=$(echo "scale=2; $sum / $count" | bc) + echo "Mean: $mean" + else + echo "No numbers provided to calculate mean" + fi + ;; + *) + echo "Invalid option. Usage: $0 {-m|-s|-e|-o} number1 number2 ..." >&2 + exit 1 + ;; +esac + +exit 0 \ No newline at end of file From e1480a4197642adebd3f98b5183e958b71e625a0 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:51:35 +0300 Subject: [PATCH 10/31] Update kirill --- courses/bash/ex05/kirill | 5 ----- 1 file changed, 5 deletions(-) diff --git a/courses/bash/ex05/kirill b/courses/bash/ex05/kirill index 77e9e1e2..cf7aa5a1 100644 --- a/courses/bash/ex05/kirill +++ b/courses/bash/ex05/kirill @@ -1,22 +1,18 @@ #!/bin/bash -# Check if at least one argument is provided if [ "$#" -lt 2 ]; then echo "Usage: $0 {-m|-s|-e|-o} number1 number2 ..." >&2 exit 1 fi -# Get the operation argument operation=$1 shift -# Initialize variables sum=0 count=0 even_sum=0 odd_sum=0 -# Loop through all the numbers provided for number in "$@"; do sum=$(echo "$sum + $number" | bc) count=$((count + 1)) @@ -27,7 +23,6 @@ for number in "$@"; do fi done -# Perform the required operation case $operation in -s) echo "Sum: $sum" From fe18281456d6ac77d0a394769896c11e58d784ab Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:54:21 +0300 Subject: [PATCH 11/31] Update ex06 --- courses/bash/ex06/kirill | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 courses/bash/ex06/kirill diff --git a/courses/bash/ex06/kirill b/courses/bash/ex06/kirill new file mode 100644 index 00000000..ede58089 --- /dev/null +++ b/courses/bash/ex06/kirill @@ -0,0 +1,17 @@ + #!/bin/bash + +map() { + if [ "$#" -lt 2 ]; then + echo "Usage: map command arg1 arg2 ..." + return 1 + fi + + command=$1 + shift + + for arg in "$@"; do + $command "$arg" + done +} + + From b5c8f760ba14dbcbdefb9e6baf0123f54c1a095e Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:55:18 +0300 Subject: [PATCH 12/31] Update ex07 --- courses/bash/ex07/kirill | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 courses/bash/ex07/kirill diff --git a/courses/bash/ex07/kirill b/courses/bash/ex07/kirill new file mode 100644 index 00000000..e09145a5 --- /dev/null +++ b/courses/bash/ex07/kirill @@ -0,0 +1,5 @@ +head -n surnames.txt > surnames_n_lines.txt + +grep "Q-Chem" surnames_n_lines.txt | sed -e 's/[[:alpha:]]\.//g' -e 's/[^a-zA-Z,-]//g' -e 's/,/\n/g' + +head -n surnames.txt > surnames_n_lines.txt && grep "Q-Chem" surnames_n_lines.txt | sed -e 's/[[:alpha:]]\.//g' -e 's/[^a-zA-Z,-]//g' -e 's/,/\n/g' \ No newline at end of file From c809e7fd3dfd1e6d071a7c4138af8e3147bf874e Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:55:51 +0300 Subject: [PATCH 13/31] Update kirill --- courses/bash/ex07/kirill | 5 ----- 1 file changed, 5 deletions(-) diff --git a/courses/bash/ex07/kirill b/courses/bash/ex07/kirill index e09145a5..e69de29b 100644 --- a/courses/bash/ex07/kirill +++ b/courses/bash/ex07/kirill @@ -1,5 +0,0 @@ -head -n surnames.txt > surnames_n_lines.txt - -grep "Q-Chem" surnames_n_lines.txt | sed -e 's/[[:alpha:]]\.//g' -e 's/[^a-zA-Z,-]//g' -e 's/,/\n/g' - -head -n surnames.txt > surnames_n_lines.txt && grep "Q-Chem" surnames_n_lines.txt | sed -e 's/[[:alpha:]]\.//g' -e 's/[^a-zA-Z,-]//g' -e 's/,/\n/g' \ No newline at end of file From ae46c7446e400cc46ccf48cd5a6488dfb7466d7c Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:57:42 +0300 Subject: [PATCH 14/31] Update ex09 --- courses/bash/ex09/kirill | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 courses/bash/ex09/kirill diff --git a/courses/bash/ex09/kirill b/courses/bash/ex09/kirill new file mode 100644 index 00000000..ae417d9a --- /dev/null +++ b/courses/bash/ex09/kirill @@ -0,0 +1,79 @@ +#!/bin/bash + +usage() { + echo "Usage: $0 [OPTIONS] FILE" + echo "Options:" + echo " -u, --url Extract URLs from the file" + echo " -e, --email Extract emails from the file" + echo " -h, --help Display this help and exit" +} + +extract_urls() { + grep -oE 'https?://[^\s/$.?#].[^\s]*' "$1" +} + +extract_emails() { + grep -oE '[\w._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' "$1" +} + +options=$(getopt -o ueh --long url,email,help -- "$@") +if [ $? -ne 0 ]; then + usage + exit 1 +fi + +eval set -- "$options" + +url_flag=false +email_flag=false + +while true; do + case "$1" in + -u | --url) + url_flag=true + shift + ;; + -e | --email) + email_flag=true + shift + ;; + -h | --help) + usage + exit 0 + ;; + --) + shift + break + ;; + *) + usage + exit 1 + ;; + esac +done + + is provided +if ! $url_flag && ! $email_flag; then + echo "Error: You must specify at least one option (--url or --email)." + usage + exit 1 +fi + + +if [ $# -ne 1 ]; then + echo "Error: You must specify a file." + usage + exit 1 +fi + + file +file="$1" +if $url_flag; then + echo "Extracting URLs from $file:" + extract_urls "$file" +fi + +if $email_flag; then + echo "Extracting emails from $file:" + extract_emails "$file" +fi \ No newline at end of file From 5a5eb1e5a9fe2b319b5ca6650144e13a4f61ad19 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Thu, 25 Jul 2024 12:59:29 +0300 Subject: [PATCH 15/31] Update ex10 --- courses/bash/ex10/kirill | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 courses/bash/ex10/kirill diff --git a/courses/bash/ex10/kirill b/courses/bash/ex10/kirill new file mode 100644 index 00000000..ff2b3679 --- /dev/null +++ b/courses/bash/ex10/kirill @@ -0,0 +1,13 @@ +#!/bin/bash + ' + BEGIN { + + line_count = 0; + } + { + line_count++; + } + END { + print line_count; + } +' "$@" \ No newline at end of file From 3269cc25480e6221fdf7a19acef2dc269f24c312 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Mon, 5 Aug 2024 17:55:30 +0300 Subject: [PATCH 16/31] Update strlen.c --- courses/cunix/ex01/src/strlen.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/courses/cunix/ex01/src/strlen.c b/courses/cunix/ex01/src/strlen.c index 34fde5ef..a777d22f 100644 --- a/courses/cunix/ex01/src/strlen.c +++ b/courses/cunix/ex01/src/strlen.c @@ -1,11 +1,15 @@ #include -#include "my_strlen.h" +size_t my_strlen(const char *str) { + const char *s = str; + while (*s != '\0') { + s++; + } + return s - str; +} int main() { - const char *test_str = "Hello, World!"; - int length = my_strlen(test_str); - - printf("Length of the string is: %d\n", length); - + const char *my_string = "Hello, World!"; + size_t length = my_strlen(my_string); + printf("Length of the string is %zu\n", length); return 0; } From 9a3b81021b06f999b422a4bb31947d18363ae797 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Tue, 6 Aug 2024 10:11:19 +0300 Subject: [PATCH 17/31] Rename kirill to ex01.sh --- courses/bash/ex02/{kirill => ex01.sh} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename courses/bash/ex02/{kirill => ex01.sh} (98%) diff --git a/courses/bash/ex02/kirill b/courses/bash/ex02/ex01.sh similarity index 98% rename from courses/bash/ex02/kirill rename to courses/bash/ex02/ex01.sh index 023ec6c6..18af4b5b 100644 --- a/courses/bash/ex02/kirill +++ b/courses/bash/ex02/ex01.sh @@ -14,4 +14,4 @@ find . -type d | while read -r dir; do if echo "$rel_path" | grep -w -q "$pattern"; then echo "$rel_path" fi -done \ No newline at end of file +done From ef89bcd9d55d93632c270523368ce6cd0c45614c Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 14:19:24 +0300 Subject: [PATCH 18/31] Rename kirill to ex03.sh --- courses/bash/ex03/{kirill => ex03.sh} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename courses/bash/ex03/{kirill => ex03.sh} (98%) diff --git a/courses/bash/ex03/kirill b/courses/bash/ex03/ex03.sh similarity index 98% rename from courses/bash/ex03/kirill rename to courses/bash/ex03/ex03.sh index cb4125cb..8d3ec4f0 100644 --- a/courses/bash/ex03/kirill +++ b/courses/bash/ex03/ex03.sh @@ -28,4 +28,4 @@ search_keyword "$keyword1" search_keyword "$keyword2" search_keyword "$keyword3" -exit 0 \ No newline at end of file +exit 0 From 214dc52d434f47b26c2bb333bd3fbe57359444a1 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 14:55:39 +0300 Subject: [PATCH 19/31] Create ex02.sh --- courses/bash/ex02/ex02.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 courses/bash/ex02/ex02.sh diff --git a/courses/bash/ex02/ex02.sh b/courses/bash/ex02/ex02.sh new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/courses/bash/ex02/ex02.sh @@ -0,0 +1 @@ + From 981d7a538a0ee5af34f01f5615b4d68d645f3b3d Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 15:01:13 +0300 Subject: [PATCH 20/31] Update ex02.sh --- courses/bash/ex02/ex02.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/courses/bash/ex02/ex02.sh b/courses/bash/ex02/ex02.sh index 8b137891..5f7bb8f4 100644 --- a/courses/bash/ex02/ex02.sh +++ b/courses/bash/ex02/ex02.sh @@ -1 +1,15 @@ +#!/bin/bash +if [ "$#" -ne 1 ]; then + echo "Usage: $0 'pattern'" + exit 1 +fi + +pattern=$1 + +find . -type d | while read -r dir; do + rel_path=${dir#./} + if echo "$rel_path" | grep -w -q "$pattern"; then + echo "$rel_path" + fi +done From ae0416cada22e438d079b1d0ac4d6e8edc894ecd Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 15:23:34 +0300 Subject: [PATCH 21/31] Rename kirill to ex04.sh --- courses/bash/ex04/{kirill => ex04.sh} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename courses/bash/ex04/{kirill => ex04.sh} (96%) diff --git a/courses/bash/ex04/kirill b/courses/bash/ex04/ex04.sh similarity index 96% rename from courses/bash/ex04/kirill rename to courses/bash/ex04/ex04.sh index 317e7c2c..d8f3dc53 100644 --- a/courses/bash/ex04/kirill +++ b/courses/bash/ex04/ex04.sh @@ -12,4 +12,4 @@ find . -type f | while read -r file; do grep -Hn "$pattern" "$file" done -exit 0 \ No newline at end of file +exit 0 From df4c153c42c798168e737b557baae3786d2e30b8 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 15:28:29 +0300 Subject: [PATCH 22/31] Rename kirill to ex05.sh --- courses/bash/ex05/{kirill => ex05.sh} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename courses/bash/ex05/{kirill => ex05.sh} (99%) diff --git a/courses/bash/ex05/kirill b/courses/bash/ex05/ex05.sh similarity index 99% rename from courses/bash/ex05/kirill rename to courses/bash/ex05/ex05.sh index cf7aa5a1..d911e4bf 100644 --- a/courses/bash/ex05/kirill +++ b/courses/bash/ex05/ex05.sh @@ -47,4 +47,4 @@ case $operation in ;; esac -exit 0 \ No newline at end of file +exit 0 From ae29dcdc9fbc286ab0ccddc1890e160738e6e9aa Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 15:30:33 +0300 Subject: [PATCH 23/31] Rename kirill to ex06.sh --- courses/bash/ex06/{kirill => ex06.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename courses/bash/ex06/{kirill => ex06.sh} (100%) diff --git a/courses/bash/ex06/kirill b/courses/bash/ex06/ex06.sh similarity index 100% rename from courses/bash/ex06/kirill rename to courses/bash/ex06/ex06.sh From 863cd909b49a12cae7ef41056d726914432275a8 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 15:31:55 +0300 Subject: [PATCH 24/31] Rename kirill to ex09.sh --- courses/bash/ex09/{kirill => ex09.sh} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename courses/bash/ex09/{kirill => ex09.sh} (99%) diff --git a/courses/bash/ex09/kirill b/courses/bash/ex09/ex09.sh similarity index 99% rename from courses/bash/ex09/kirill rename to courses/bash/ex09/ex09.sh index ae417d9a..d42a3848 100644 --- a/courses/bash/ex09/kirill +++ b/courses/bash/ex09/ex09.sh @@ -76,4 +76,4 @@ fi if $email_flag; then echo "Extracting emails from $file:" extract_emails "$file" -fi \ No newline at end of file +fi From 82a79d32ab0ed50976cfc85885fa44db1f2cbb30 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Wed, 7 Aug 2024 15:36:42 +0300 Subject: [PATCH 25/31] Delete courses/bash/ex10/kirill --- courses/bash/ex10/kirill | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 courses/bash/ex10/kirill diff --git a/courses/bash/ex10/kirill b/courses/bash/ex10/kirill deleted file mode 100644 index ff2b3679..00000000 --- a/courses/bash/ex10/kirill +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - ' - BEGIN { - - line_count = 0; - } - { - line_count++; - } - END { - print line_count; - } -' "$@" \ No newline at end of file From 918da52debb07f46db89b24f55ca56b0d6396dff Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Sun, 18 Aug 2024 13:13:53 +0300 Subject: [PATCH 26/31] Update ex02.sh --- courses/bash/ex02/ex02.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/courses/bash/ex02/ex02.sh b/courses/bash/ex02/ex02.sh index 5f7bb8f4..18af4b5b 100644 --- a/courses/bash/ex02/ex02.sh +++ b/courses/bash/ex02/ex02.sh @@ -8,7 +8,9 @@ fi pattern=$1 find . -type d | while read -r dir; do + # Get the relative path rel_path=${dir#./} + if echo "$rel_path" | grep -w -q "$pattern"; then echo "$rel_path" fi From 7c8f6eaa1644cd008daed6d9926e9e2a098ef768 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Mon, 19 Aug 2024 00:48:31 +0300 Subject: [PATCH 27/31] Update ex03.sh --- courses/bash/ex03/ex03.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/courses/bash/ex03/ex03.sh b/courses/bash/ex03/ex03.sh index 8d3ec4f0..34ea4a88 100644 --- a/courses/bash/ex03/ex03.sh +++ b/courses/bash/ex03/ex03.sh @@ -1,7 +1,7 @@ - #!/bin/bash +#!/bin/bash if [ "$#" -ne 4 ]; then - echo "Usage: $0 filename keyword1 keyword2 keyword3" >&2 + echo "Usage: $0 filename keyword1 keyword2 keyword3" exit 1 fi @@ -10,22 +10,21 @@ keyword1=$2 keyword2=$3 keyword3=$4 -if [ ! -r "$filename" ]; then +if [ ! -f "$filename" ]; then + echo "File '$filename' not found!" exit 1 fi + search_keyword() { local keyword=$1 - local matches - matches=$(grep -c "$keyword" "$filename") echo "Keyword: $keyword" - echo "Number of matches: $matches" - grep "$keyword" "$filename" - echo "" + count=$(grep -c "$keyword" "$filename") + echo "Number of matches: $count" + grep -n "$keyword" "$filename" || true + echo } search_keyword "$keyword1" search_keyword "$keyword2" search_keyword "$keyword3" - -exit 0 From e3d68cf7291650eeeba675a61132dba8423f204b Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Mon, 19 Aug 2024 01:06:27 +0300 Subject: [PATCH 28/31] Update ex04.sh --- courses/bash/ex04/ex04.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/courses/bash/ex04/ex04.sh b/courses/bash/ex04/ex04.sh index d8f3dc53..92b7c7f7 100644 --- a/courses/bash/ex04/ex04.sh +++ b/courses/bash/ex04/ex04.sh @@ -1,15 +1,15 @@ #!/bin/bash -if [ "$#" -ne 1 ]; then - echo "Usage: $0 pattern" >&2 +echo "Searching for pattern: $1" + +if [ -z "$1" ]; then + echo "Usage: $0 pattern" exit 1 fi -pattern=$1 +pattern="$1" find . -type f | while read -r file; do - - grep -Hn "$pattern" "$file" + echo "Checking file: $file" + grep -nH "$pattern" "$file" 2>/dev/null done - -exit 0 From 7cd6283ae6378febf3b53a2ef1d19de413bef131 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Mon, 19 Aug 2024 01:09:29 +0300 Subject: [PATCH 29/31] Update ex05.sh From 04302097c37e76dc675e9861c20ceb5ea5c7a6da Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Mon, 19 Aug 2024 01:09:41 +0300 Subject: [PATCH 30/31] Update ex05.sh From 385fbd8f4339439cb89abfb442e867ec501c8be0 Mon Sep 17 00:00:00 2001 From: kirill1261 Date: Mon, 19 Aug 2024 01:12:17 +0300 Subject: [PATCH 31/31] Update ex06.sh --- courses/bash/ex06/ex06.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/courses/bash/ex06/ex06.sh b/courses/bash/ex06/ex06.sh index ede58089..d960cfed 100644 --- a/courses/bash/ex06/ex06.sh +++ b/courses/bash/ex06/ex06.sh @@ -6,7 +6,7 @@ map() { return 1 fi - command=$1 + local command=$1 shift for arg in "$@"; do