From 359d783e024752cb154e0df6e39a49d57d5c4484 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 14:25:59 +0000 Subject: [PATCH 01/28] listing the files --- individual-shell-tools/ls/script-01.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/individual-shell-tools/ls/script-01.sh b/individual-shell-tools/ls/script-01.sh index 241b62f..1a7ff0a 100755 --- a/individual-shell-tools/ls/script-01.sh +++ b/individual-shell-tools/ls/script-01.sh @@ -13,3 +13,6 @@ fi # TODO: Write a command to list the files and folders in this directory. # The output should be a list of names including child-directory, script-01.sh, script-02.sh, and more. + +ls # which stands to the list + From 4cc02d0a91751678d9cf40b06ff282b8dd74883e Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 14:29:49 +0000 Subject: [PATCH 02/28] listing the files command --- individual-shell-tools/ls/script-01.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/individual-shell-tools/ls/script-01.sh b/individual-shell-tools/ls/script-01.sh index 1a7ff0a..21c0432 100755 --- a/individual-shell-tools/ls/script-01.sh +++ b/individual-shell-tools/ls/script-01.sh @@ -14,5 +14,5 @@ fi # TODO: Write a command to list the files and folders in this directory. # The output should be a list of names including child-directory, script-01.sh, script-02.sh, and more. -ls # which stands to the list +ls # the commmand to list the files From dff5a9e7e0820e333b362e1f0040ebf39516bee5 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 14:51:21 +0000 Subject: [PATCH 03/28] listing all the files in the directory child-directory --- individual-shell-tools/ls/script-02.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/individual-shell-tools/ls/script-02.sh b/individual-shell-tools/ls/script-02.sh index d0a5a10..6070711 100755 --- a/individual-shell-tools/ls/script-02.sh +++ b/individual-shell-tools/ls/script-02.sh @@ -4,3 +4,6 @@ set -euo pipefail # TODO: Write a command which lists all of the files in the directory named child-directory. # The output should be a list of names: helper-1.txt, helper-2.txt, helper-3.txt. + +# I first typed command ls -l which gives me the files list and then +ls child-directory From 290aac54274e8b4581427e06c4106409245ef542 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 14:55:27 +0000 Subject: [PATCH 04/28] Ls -R command to give the overview of the folders in the directory, also the level below, the overview of the files in the folders --- individual-shell-tools/ls/script-03.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/individual-shell-tools/ls/script-03.sh b/individual-shell-tools/ls/script-03.sh index 781216d..f11a173 100755 --- a/individual-shell-tools/ls/script-03.sh +++ b/individual-shell-tools/ls/script-03.sh @@ -5,3 +5,5 @@ set -euo pipefail # TODO: Write a command which _recursively_ lists all of the files and folders in this directory _and_ all of the files inside those folders. # The output should be a list of names including: child-directory, script-01.sh, helper-1.txt (and more). # The formatting of the output doesn't matter. + +ls -R From 42c8f5c16d6e1d4427e5075158329202377a237c Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 15:33:40 +0000 Subject: [PATCH 05/28] sorting command the newest to oldest and oldest to the first --- individual-shell-tools/ls/script-04.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/individual-shell-tools/ls/script-04.sh b/individual-shell-tools/ls/script-04.sh index 72f3817..c4db486 100755 --- a/individual-shell-tools/ls/script-04.sh +++ b/individual-shell-tools/ls/script-04.sh @@ -16,8 +16,11 @@ echo "First exercise (sorted newest to oldest):" # TODO: Write a command which lists the files in the child-directory directory, one per line, sorted so that the most recently modified file is first. # The output should be a list of names in this order, one per line: helper-3.txt, helper-1.txt, helper-2.txt. +ls -t child-directory # sorts from the newest to the oldest echo "Second exercise (sorted oldest to newest):" # TODO: Write a command which does the same as above, but sorted in the opposite order (oldest first). # The output should be a list of names in this order, one per line: helper-2.txt, helper-1.txt, helper-3.txt. + +ls -tr child- directory From c531f855d87edd88b24b509e91a15b4e32561b81 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 15:43:12 +0000 Subject: [PATCH 06/28] cat accesses the files and than the content of the files and prints it in the terminal --- individual-shell-tools/cat/script-01.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/individual-shell-tools/cat/script-01.sh b/individual-shell-tools/cat/script-01.sh index c85053e..8264d75 100755 --- a/individual-shell-tools/cat/script-01.sh +++ b/individual-shell-tools/cat/script-01.sh @@ -4,3 +4,5 @@ set -euo pipefail # TODO: Write a command to output the contents of the helper-1.txt file inside the helper-files directory to the terminal. # The output of this command should be "Once upon a time...". + +cat ..helper-files/helper-1.txt From 7676f78e3628fcb0e4a033f691f8ae87926a6056 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 15:45:40 +0000 Subject: [PATCH 07/28] cat command to access the content of all the files through * and print the output in the terminal --- individual-shell-tools/cat/script-02.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/individual-shell-tools/cat/script-02.sh b/individual-shell-tools/cat/script-02.sh index 01bbd5e..927e748 100755 --- a/individual-shell-tools/cat/script-02.sh +++ b/individual-shell-tools/cat/script-02.sh @@ -11,3 +11,5 @@ set -euo pipefail # It looked delicious. # I was tempted to take a bite of it. # But this seemed like a bad idea... + +cat ../helper-files/*.text # I got hungry when reading the output From c8c9c4a29fd79c6eb13d0577022c1af8841ae488 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 15:50:06 +0000 Subject: [PATCH 08/28] use of cat and pipe and nl to number the output in the file --- individual-shell-tools/cat/script-03.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/individual-shell-tools/cat/script-03.sh b/individual-shell-tools/cat/script-03.sh index 37573b0..8f673d8 100755 --- a/individual-shell-tools/cat/script-03.sh +++ b/individual-shell-tools/cat/script-03.sh @@ -9,3 +9,5 @@ set -euo pipefail # 1 It looked delicious. # 2 I was tempted to take a bite of it. # 3 But this seemed like a bad idea... + +cat ../helper-files/helper-3.txt | nl # ordered by numbers From 10e5c1ddcefdfba393066f4e6ddfcfb57538525d Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 15:59:25 +0000 Subject: [PATCH 09/28] cat -n and cat | nl commands to number the lines --- individual-shell-tools/cat/script-04-stretch.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/individual-shell-tools/cat/script-04-stretch.sh b/individual-shell-tools/cat/script-04-stretch.sh index 00fe3c4..56c23bc 100755 --- a/individual-shell-tools/cat/script-04-stretch.sh +++ b/individual-shell-tools/cat/script-04-stretch.sh @@ -13,3 +13,8 @@ set -euo pipefail # 3 It looked delicious. # 4 I was tempted to take a bite of it. # 5 But this seemed like a bad idea... + +# i didn't get this phrase "we want line numbers not to reset at the start of each file." +# so there are two ways to do it +cat -n ../helper-files/*txt # -n number the blank lines and filled out lines +cat ../helper-files/*.txt |nl # skips the blank lines and comes only filled out lines From 91e1f2aabfae98b795af4527768dad7fecf7a18e Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:10:12 +0000 Subject: [PATCH 10/28] counting words via wc -c --- individual-shell-tools/cat/script-04-stretch.sh | 2 +- individual-shell-tools/wc/script-01.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/individual-shell-tools/cat/script-04-stretch.sh b/individual-shell-tools/cat/script-04-stretch.sh index 56c23bc..aaca0e0 100755 --- a/individual-shell-tools/cat/script-04-stretch.sh +++ b/individual-shell-tools/cat/script-04-stretch.sh @@ -17,4 +17,4 @@ set -euo pipefail # i didn't get this phrase "we want line numbers not to reset at the start of each file." # so there are two ways to do it cat -n ../helper-files/*txt # -n number the blank lines and filled out lines -cat ../helper-files/*.txt |nl # skips the blank lines and comes only filled out lines +cat ../helper-files/*.txt | nl # skips the blank lines and comes only filled out lines diff --git a/individual-shell-tools/wc/script-01.sh b/individual-shell-tools/wc/script-01.sh index c9dd6e5..bf691c5 100755 --- a/individual-shell-tools/wc/script-01.sh +++ b/individual-shell-tools/wc/script-01.sh @@ -4,3 +4,5 @@ set -euo pipefail # TODO: Write a command to output the number of words in the file helper-files/helper-3.txt. # The output should include the number 19. The output should not include the number 92. + +wc -w ../helper-files/helper-3.txt From 0e2e1f8b037cc2e006f8f83b1411764b7086409e Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:27:06 +0000 Subject: [PATCH 11/28] wc - l to output the number of lines in the file --- individual-shell-tools/wc/script-02.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/individual-shell-tools/wc/script-02.sh b/individual-shell-tools/wc/script-02.sh index 8feeb1a..59d0713 100755 --- a/individual-shell-tools/wc/script-02.sh +++ b/individual-shell-tools/wc/script-02.sh @@ -4,3 +4,5 @@ set -euo pipefail # TODO: Write a command to output the number of lines in the file helper-files/helper-3.txt. # The output should include the number 3. The output should not include the number 19. + +wc -l ../helper-files/helper-3.txt # it gives the 3 lines of the text in the file From a2447f2794c1bcc81d7ff6e311b42fd3461c8f40 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:28:59 +0000 Subject: [PATCH 12/28] the use of star to output all info --- individual-shell-tools/wc/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/wc/script-03.sh b/individual-shell-tools/wc/script-03.sh index 6b2e9d3..806e3a0 100755 --- a/individual-shell-tools/wc/script-03.sh +++ b/individual-shell-tools/wc/script-03.sh @@ -8,3 +8,4 @@ set -euo pipefail # 1 7 39 ../helper-files/helper-2.txt # 3 19 92 ../helper-files/helper-3.txt # 5 30 151 total +wc ../helper-files/*.txt # the same as with cat the star * From c94f2276a21e20878c34d2d6efa95b6f4726bdc6 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:36:11 +0000 Subject: [PATCH 13/28] using carrot ^ to search doctor dialogue --- individual-shell-tools/grep/script-01.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/individual-shell-tools/grep/script-01.sh b/individual-shell-tools/grep/script-01.sh index fb05f42..07361cf 100755 --- a/individual-shell-tools/grep/script-01.sh +++ b/individual-shell-tools/grep/script-01.sh @@ -4,3 +4,12 @@ set -euo pipefail # TODO: Write a command to output every line in dialogue.txt said by the Doctor. # The output should contain 6 lines. + +grep ^Doctor dialogue.txt # i tried to use the "" quotes but my terminal didnt accept that + +Doctor: Hello +Doctor: What's wrong today? +Doctor: That sounds frustrating. When did this start? +Doctor: Say "Hi". +Doctor: You didn't say hello +Doctor: You're welcome, goodbye From 5d9f79ef5898d714f6bc2c2cc908bf05981ef552 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:42:33 +0000 Subject: [PATCH 14/28] grep -i to output every line of the dialogue which contrains the word doctor --- individual-shell-tools/grep/script-02.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/individual-shell-tools/grep/script-02.sh b/individual-shell-tools/grep/script-02.sh index df6f856..3d973e4 100755 --- a/individual-shell-tools/grep/script-02.sh +++ b/individual-shell-tools/grep/script-02.sh @@ -4,3 +4,15 @@ set -euo pipefail # TODO: Write a command to output every line in dialogue.txt that contains the word Doctor (regardless of case). # The output should contain 9 lines. + +grep -i Doctor dialogue.txt + +Doctor: Hello +Patient: Hello Doctor +Doctor: What's wrong today? +Doctor: That sounds frustrating. When did this start? +Doctor: Say "Hi". +Doctor: You didn't say hello +Doctor: You're welcome, goodbye +Patient: I went to the doctor! +Spouse: I'm glad you saw the Doctor: did they cure you? From 9421db12327a8d88d0a14d848e6ba4ce8dc49fea Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:44:31 +0000 Subject: [PATCH 15/28] output of 9 lines using -ic command in grep --- individual-shell-tools/grep/script-03.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/individual-shell-tools/grep/script-03.sh b/individual-shell-tools/grep/script-03.sh index 5383fe5..e9271dc 100755 --- a/individual-shell-tools/grep/script-03.sh +++ b/individual-shell-tools/grep/script-03.sh @@ -4,3 +4,6 @@ set -euo pipefail # TODO: Write a command to output the number of lines in dialogue.txt that contain the word Doctor (regardless of case). # The output should be exactly the number 9. + +rep Doctor -ic dialogue.txt +9 From d653d6414fe956e697b3c798c074b89d44789853 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:47:54 +0000 Subject: [PATCH 16/28] excluding a word using a -iv command --- individual-shell-tools/grep/script-04.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/individual-shell-tools/grep/script-04.sh b/individual-shell-tools/grep/script-04.sh index 80ee047..a00152b 100755 --- a/individual-shell-tools/grep/script-04.sh +++ b/individual-shell-tools/grep/script-04.sh @@ -4,3 +4,16 @@ set -euo pipefail # TODO: Write a command to output every line in dialogue.txt that does not contain the word "Hello" (regardless of case). # The output should contain 10 lines. + +grep hello -iv dialogue.txt + +Doctor: What's wrong today? +Doctor: That sounds frustrating. When did this start? +Doctor: Say "Hi". +Patient: Hi +Patient: I seem to be cured! +Doctor: You're welcome, goodbye + +Patient: I went to the doctor! +Spouse: I'm glad you saw the Doctor: did they cure you? +Patient: Yes! From d4199c96a8459d4707fcbac4a3f840c505f93054 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:49:43 +0000 Subject: [PATCH 17/28] matching the string and finding the line before the string occurs using -B1 command --- individual-shell-tools/grep/script-05.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/individual-shell-tools/grep/script-05.sh b/individual-shell-tools/grep/script-05.sh index 1eb5381..211e6dc 100755 --- a/individual-shell-tools/grep/script-05.sh +++ b/individual-shell-tools/grep/script-05.sh @@ -4,3 +4,11 @@ set -euo pipefail # TODO: Write a command to output every line in dialogue.txt that contains the string "cure", as well as the line before that line. # The output should contain two pairs of two lines of text (with a separator between them). + +grep cure -B1 dialogue.txt + +Doctor: You didn't say hello +Patient: I seem to be cured! +-- +Patient: I went to the doctor! +Spouse: I'm glad you saw the Doctor: did they cure you? From cb36d544dcb0564a7ecbf651436f5ea6045044cf Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 16:51:45 +0000 Subject: [PATCH 18/28] pattern matching using command -il and * to look in every txt file --- individual-shell-tools/grep/script-06.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/individual-shell-tools/grep/script-06.sh b/individual-shell-tools/grep/script-06.sh index 5670e3b..2761722 100755 --- a/individual-shell-tools/grep/script-06.sh +++ b/individual-shell-tools/grep/script-06.sh @@ -4,3 +4,9 @@ set -euo pipefail # TODO: Write a command to output the name of every `.txt` file in this directory which contains a line of dialogue said by the Doctor. # The output should contain two filenames. + +grep Doctor -il *.txt + +dialogue.txt +dialogue-2.txt +dialogue-3.txt From 3194ddb0fae5a255927fb7914576b3000031d41e Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:06:19 +0000 Subject: [PATCH 19/28] grep -c to output lines of the searchname --- individual-shell-tools/grep/script-07.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/individual-shell-tools/grep/script-07.sh b/individual-shell-tools/grep/script-07.sh index 9670eba..3aa463f 100755 --- a/individual-shell-tools/grep/script-07.sh +++ b/individual-shell-tools/grep/script-07.sh @@ -4,3 +4,16 @@ set -euo pipefail # TODO: Write a command to output, for each `.txt` file in this directory, how many lines of dialogue the Doctor has. # The output should show that dialogue.txt contains 6 lines, dialogue-2.txt contains 2, and dialogue-3.txt contains 0. + +grep ^Doctor -c *.txt # this command gaves the expected output + +dialogue.txt:6 +dialogue-2.txt:2 +dialogue-3.txt:0 + +grep ^ Doctor -c *.txt # however here i put a space between the carrot and the search name and it gave me a different output, and i dont know why + +grep: Doctor: No such file or directory +dialogue.txt:15 +dialogue-2.txt:4 +dialogue-3.txt:3 From 50b4d2365a0c0c1df019f700c0e08b52df84aaee Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:09:09 +0000 Subject: [PATCH 20/28] checking occurencies with sed --- individual-shell-tools/sed/script-01.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/individual-shell-tools/sed/script-01.sh b/individual-shell-tools/sed/script-01.sh index 3eba6fa..5c6e365 100755 --- a/individual-shell-tools/sed/script-01.sh +++ b/individual-shell-tools/sed/script-01.sh @@ -5,3 +5,17 @@ set -euo pipefail # TODO: Write a command to output input.txt with all occurrences of the letter `i` replaced with `I`. # The output should contain 11 lines. # The first line of the output should be: "ThIs Is a sample fIle for experImentIng with sed.". + +sed s/i/I/g input.txt + +ThIs Is a sample fIle for experImentIng wIth sed. + +It contaIns many lInes, and there are some thIngs you may want to do wIth each of them. + +We'll Include some score InformatIon: +37 AlIsha +15 Jacob +7 PIetro +3 Katya + +We also should remember, when we go shoppIng, to get 4 Items: oranges,cheese,bread,olIves. From 55bc0ea39aa0753b2a8b001521c5740e6c1d8953 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:16:38 +0000 Subject: [PATCH 21/28] numbers removed using sed --- individual-shell-tools/sed/script-02.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/individual-shell-tools/sed/script-02.sh b/individual-shell-tools/sed/script-02.sh index abdd64d..c4bdd6a 100755 --- a/individual-shell-tools/sed/script-02.sh +++ b/individual-shell-tools/sed/script-02.sh @@ -5,3 +5,17 @@ set -euo pipefail # TODO: Write a command to output input.txt with numbers removed. # The output should contain 11 lines. # Line 6 of the output should be " Alisha". + +sed 's/[0-9]*//g' input.txt # however Alisha is not on the 6 line + +This is a sample file for experimenting with sed. + +It contains many lines, and there are some things you may want to do with each of them. + +We'll include some score information: + Alisha + Jacob + Pietro + Katya + +We also should remember, when we go shopping, to get items: oranges,cheese,bread,olives. From feadae87a5f66c1fcc48378cc1074cbf53434fc7 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:19:24 +0000 Subject: [PATCH 22/28] removing number using sed --- individual-shell-tools/sed/script-03.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/individual-shell-tools/sed/script-03.sh b/individual-shell-tools/sed/script-03.sh index dd284a2..91cffd9 100755 --- a/individual-shell-tools/sed/script-03.sh +++ b/individual-shell-tools/sed/script-03.sh @@ -4,3 +4,11 @@ set -euo pipefail # TODO: Write a command to output input.txt removing any line which contains a number. # The output should contain 6 lines. + +sed -e '/[0-9]/d' input.txt # my output is only 4 lines instead of 6 + +This is a sample file for experimenting with sed. + +It contains many lines, and there are some things you may want to do with each of them. + +We'll include some score information: From 3e7dec92a4f1a6ea31ac1833f3158d7fe6626379 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:21:23 +0000 Subject: [PATCH 23/28] sed command to replace the words --- individual-shell-tools/sed/script-04.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/individual-shell-tools/sed/script-04.sh b/individual-shell-tools/sed/script-04.sh index 0052ac6..bb4e413 100755 --- a/individual-shell-tools/sed/script-04.sh +++ b/individual-shell-tools/sed/script-04.sh @@ -4,3 +4,17 @@ set -euo pipefail # TODO: Write a command to output input.txt replacing every occurrence of the string "We'll" with "We will". # The output should contain 11 lines. + +sed "s/We'll/We will/g" input.txt + +This is a sample file for experimenting with sed. + +It contains many lines, and there are some things you may want to do with each of them. + +We will include some score information: +37 Alisha +15 Jacob +7 Pietro +3 Katya + +We also should remember, when we go shopping, to get 4 items: oranges,cheese,bread,olives. From 66fcffae05e3ab0287768015bc0204320468d4ab Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:24:17 +0000 Subject: [PATCH 24/28] moved the number to the end of the name using sed command --- individual-shell-tools/sed/script-05.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/individual-shell-tools/sed/script-05.sh b/individual-shell-tools/sed/script-05.sh index 2dcc91a..cea5a53 100755 --- a/individual-shell-tools/sed/script-05.sh +++ b/individual-shell-tools/sed/script-05.sh @@ -6,3 +6,17 @@ set -euo pipefail # If a line starts with a number and a space, make the line instead end with a space and the number. # So line 6 which currently reads "37 Alisha" should instead read "Alisha 37". # The output should contain 11 lines. + +sed -E 's/^([0-9]+) (.*)$/\2 \1/' input.txt + +This is a sample file for experimenting with sed. + +It contains many lines, and there are some things you may want to do with each of them. + +We'll include some score information: +Alisha 37 +Jacob 15 +Pietro 7 +Katya 3 + +We also should remember, when we go shopping, to get 4 items: oranges,cheese,bread,olives. From ab638fc387f69bb883592f06b516a262a593360c Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:26:29 +0000 Subject: [PATCH 25/28] removing commas --- individual-shell-tools/sed/script-06.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/individual-shell-tools/sed/script-06.sh b/individual-shell-tools/sed/script-06.sh index 0b93901..4de1e0e 100755 --- a/individual-shell-tools/sed/script-06.sh +++ b/individual-shell-tools/sed/script-06.sh @@ -8,3 +8,17 @@ set -euo pipefail # The output should contain 11 lines. # Line 3 should be "It contains many lines, and there are some things you may want to do with each of them.". # Line 11 should be "We also should remember, when we go shopping, to get 4 items: oranges, cheese, bread, olives.". + +sed 's/, */, /g' input.txt + +This is a sample file for experimenting with sed. + +It contains many lines, and there are some things you may want to do with each of them. + +We'll include some score information: +37 Alisha +15 Jacob +7 Pietro +3 Katya + +We also should remember, when we go shopping, to get 4 items: oranges, cheese, bread, olives. From 862c2b50a2b79cf454634bfee849542e165f7d9a Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:32:07 +0000 Subject: [PATCH 26/28] outputing the first column of the table with names --- individual-shell-tools/awk/script-01.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/individual-shell-tools/awk/script-01.sh b/individual-shell-tools/awk/script-01.sh index 8db4390..120c347 100755 --- a/individual-shell-tools/awk/script-01.sh +++ b/individual-shell-tools/awk/script-01.sh @@ -4,3 +4,12 @@ set -euo pipefail # TODO: Write a command to output just the names of each player in `scores-table.txt`. # Your output should contain 6 lines, each with just one word on it. + +awk '{print $1}' scores-table.txt + +Ahmed +Basia +Mehmet +Leila +Piotr +Chandra From a1e2f0551d98f24cf550e3577d8ad89cc76c6f00 Mon Sep 17 00:00:00 2001 From: donarbl Date: Mon, 3 Mar 2025 17:33:26 +0000 Subject: [PATCH 27/28] names and corresponding cities using awk and print command --- individual-shell-tools/awk/script-02.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/individual-shell-tools/awk/script-02.sh b/individual-shell-tools/awk/script-02.sh index 5956be9..677fb6d 100755 --- a/individual-shell-tools/awk/script-02.sh +++ b/individual-shell-tools/awk/script-02.sh @@ -4,3 +4,10 @@ set -euo pipefail # TODO: Write a command to output the names of each player, as well as their city. # Your output should contain 6 lines, each with two words on it, separated by a space. +awk '{print $1, $2}' scores-table.txt +Ahmed London +Basia London +Mehmet Birmingham +Leila London +Piotr Glasgow +Chandra Birmingham From f9b46d004e4ddf14e009d608f6e736b5d4782872 Mon Sep 17 00:00:00 2001 From: donarbl Date: Wed, 5 Mar 2025 17:38:10 +0000 Subject: [PATCH 28/28] awk exercices to extract information from columns --- individual-shell-tools/awk/script-03.sh | 7 +++++++ individual-shell-tools/awk/script-04.sh | 5 +++++ individual-shell-tools/awk/script-05.sh | 1 + individual-shell-tools/awk/script-06-stretch.sh | 1 + individual-shell-tools/awk/script-07-stretch.sh | 1 + 5 files changed, 15 insertions(+) diff --git a/individual-shell-tools/awk/script-03.sh b/individual-shell-tools/awk/script-03.sh index af7c6e8..dfbc4af 100755 --- a/individual-shell-tools/awk/script-03.sh +++ b/individual-shell-tools/awk/script-03.sh @@ -5,3 +5,10 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the score from their first attempt. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 1". +awk '{print $1, $3}' scores-table.txt +Ahmed 1 +Basia 22 +Mehmet 3 +Leila 1 +Piotr 15 +Chandra 12 diff --git a/individual-shell-tools/awk/script-04.sh b/individual-shell-tools/awk/script-04.sh index bf15703..af2837b 100755 --- a/individual-shell-tools/awk/script-04.sh +++ b/individual-shell-tools/awk/script-04.sh @@ -5,3 +5,8 @@ set -euo pipefail # TODO: Write a command to output just the names of each player in London along with the score from their last attempt. # Your output should contain 3 lines, each with one word and one number on it. # The first line should be "Ahmed 4". + +awk '/London/ { if (NF<5) print $1, $NF; else print $1, $5}' scores-table.txt +Ahmed 4 +Basia 6 +Leila 1 diff --git a/individual-shell-tools/awk/script-05.sh b/individual-shell-tools/awk/script-05.sh index d1680cb..0e36a1d 100755 --- a/individual-shell-tools/awk/script-05.sh +++ b/individual-shell-tools/awk/script-05.sh @@ -5,3 +5,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the number of times they've played the game. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 3". +awk '{print $1, NF-2}' scores-table.txt diff --git a/individual-shell-tools/awk/script-06-stretch.sh b/individual-shell-tools/awk/script-06-stretch.sh index 0201e63..fbd9cd9 100755 --- a/individual-shell-tools/awk/script-06-stretch.sh +++ b/individual-shell-tools/awk/script-06-stretch.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output the total of adding together all players' first scores. # Your output should be exactly the number 54. +awk '{sum += $3} END{print sum}' scores-table.txt diff --git a/individual-shell-tools/awk/script-07-stretch.sh b/individual-shell-tools/awk/script-07-stretch.sh index 3f71558..d441be8 100755 --- a/individual-shell-tools/awk/script-07-stretch.sh +++ b/individual-shell-tools/awk/script-07-stretch.sh @@ -7,3 +7,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the total of adding all of that player's scores. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 15". The second line should be "Basia 37" +awk '{ for(i = 3; i <= NF; i++) sum += $i; print $1, sum; sum = 0 }' scores-table.txt