From 6b65c822ce6228125b9e405d552f5dbd76695db5 Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 01:02:39 +0000 Subject: [PATCH 01/11] Use grep to list files from samples-files starting with upperCase --- shell-pipelines/ls-grep/script-01.sh | 2 ++ shell-pipelines/ls-grep/script-02.sh | 2 ++ shell-pipelines/ls-grep/script-03.sh | 2 ++ shell-pipelines/ls-grep/script-04.sh | 3 +++ 4 files changed, 9 insertions(+) diff --git a/shell-pipelines/ls-grep/script-01.sh b/shell-pipelines/ls-grep/script-01.sh index 8c7d968a..0de960ba 100755 --- a/shell-pipelines/ls-grep/script-01.sh +++ b/shell-pipelines/ls-grep/script-01.sh @@ -4,3 +4,5 @@ set -euo pipefail # TODO: Write a command to output the names of the files in the sample-files directory whose name contains at least one upper case letter. # Your output should contain 11 files. + +ls sample-files | grep "[A-Z]" diff --git a/shell-pipelines/ls-grep/script-02.sh b/shell-pipelines/ls-grep/script-02.sh index 16f5f71d..30eb3c5c 100755 --- a/shell-pipelines/ls-grep/script-02.sh +++ b/shell-pipelines/ls-grep/script-02.sh @@ -4,3 +4,5 @@ set -euo pipefail # TODO: Write a command to output the names of the files in the sample-files directory whose name starts with an upper case letter. # Your output should contain 10 files. + +ls sample-files | grep "^[A-Z]" diff --git a/shell-pipelines/ls-grep/script-03.sh b/shell-pipelines/ls-grep/script-03.sh index a302ab03..421a744c 100755 --- a/shell-pipelines/ls-grep/script-03.sh +++ b/shell-pipelines/ls-grep/script-03.sh @@ -4,3 +4,5 @@ set -euo pipefail # TODO: Write a command to output the names of the files in the sample-files directory whose name starts with an upper case letter and doesn't contain any other upper case letters. # Your output should contain 7 files. + + diff --git a/shell-pipelines/ls-grep/script-04.sh b/shell-pipelines/ls-grep/script-04.sh index c000b7e3..460bc4ed 100755 --- a/shell-pipelines/ls-grep/script-04.sh +++ b/shell-pipelines/ls-grep/script-04.sh @@ -4,3 +4,6 @@ set -euo pipefail # TODO: Write a command to count the number of files in the sample-files directory whose name starts with an upper case letter and doesn't contain any other upper case letters. # Your output should be the number 7. + +# ls sample-files | grep "^[A-Z][a-z]*$" +ls sample-files | grep -c "^[A-Z][a-z]*$" From 93b6123abe69d4ec5b7e9aceb1926728beff8db8 Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 15:48:24 +0000 Subject: [PATCH 02/11] completed sort,uniq,head,tail exercise; completed tr command exercise --- shell-pipelines/tr/script-01.sh | 2 ++ shell-pipelines/tr/script-02.sh | 2 ++ shell-pipelines/tr/text.txt | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/shell-pipelines/tr/script-01.sh b/shell-pipelines/tr/script-01.sh index 8bb0211e..63923210 100755 --- a/shell-pipelines/tr/script-01.sh +++ b/shell-pipelines/tr/script-01.sh @@ -6,3 +6,5 @@ set -euo pipefail # The author got feedback that they're using too many exclamation marks (!). # # TODO: Write a command to output the contents of text.txt with every exclamation mark (!) replaced with a full-stop (.). + + cat text.txt | tr "!" "." diff --git a/shell-pipelines/tr/script-02.sh b/shell-pipelines/tr/script-02.sh index cf3a503a..2bef7b1a 100755 --- a/shell-pipelines/tr/script-02.sh +++ b/shell-pipelines/tr/script-02.sh @@ -7,3 +7,5 @@ set -euo pipefail # so every Y should be a Z, and every Z should be a Y! # # TODO: Write a command to output the contents of text.txt with every Y and Z swapped (both upper and lower case). + +cat text.txt | tr "yYzZ" "zZyY" diff --git a/shell-pipelines/tr/text.txt b/shell-pipelines/tr/text.txt index d1beda8b..d43e7276 100644 --- a/shell-pipelines/tr/text.txt +++ b/shell-pipelines/tr/text.txt @@ -2,7 +2,7 @@ Dear Yara, Mz apologies for sending this response so late. As zou know, there's been a lot going on! -Unfortunatelz I don't think I'll be able to make it to Yimbabwe, but but sounds amaying! +Unfortunatelz I don't think I'll be able to make it to Yimbabwe, but sounds amaying! Hope zou're doing well, and enjoz the trip! From ebfc1988d291de2dc353ce3de43861bf0bb08696 Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 16:36:12 +0000 Subject: [PATCH 03/11] completed sort-uniq-head-tail execise --- shell-pipelines/sort-uniq-head-tail/10 | 0 shell-pipelines/sort-uniq-head-tail/script-01.sh | 1 + shell-pipelines/sort-uniq-head-tail/script-02.sh | 2 ++ shell-pipelines/sort-uniq-head-tail/script-03.sh | 2 ++ shell-pipelines/sort-uniq-head-tail/script-04.sh | 2 ++ shell-pipelines/sort-uniq-head-tail/script-05.sh | 2 ++ shell-pipelines/sort-uniq-head-tail/script-06.sh | 4 ++++ shell-pipelines/sort-uniq-head-tail/script-07.sh | 3 +++ 8 files changed, 16 insertions(+) create mode 100644 shell-pipelines/sort-uniq-head-tail/10 diff --git a/shell-pipelines/sort-uniq-head-tail/10 b/shell-pipelines/sort-uniq-head-tail/10 new file mode 100644 index 00000000..e69de29b diff --git a/shell-pipelines/sort-uniq-head-tail/script-01.sh b/shell-pipelines/sort-uniq-head-tail/script-01.sh index 171e1f98..845ad89d 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-01.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-01.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores-table.txt file. # TODO: Write a command to output scores-table.txt, with lines sorted by the person's name. # The first line of your output should be "Ahmed London 1 10 4" (with no quotes). And the third line should be "Chandra Birmingham 12 6". +sort scores-table.txt diff --git a/shell-pipelines/sort-uniq-head-tail/script-02.sh b/shell-pipelines/sort-uniq-head-tail/script-02.sh index 29c3c252..79fd2b6d 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-02.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-02.sh @@ -5,3 +5,5 @@ set -euo pipefail # The input for this script is the scores-table.txt file. # TODO: Write a command to output scores-table.txt, with lines sorted by the person's first score, descending. # The first line of your output should be "Basia London 22 9 6" (with no quotes). + +sort -k2 -r scores-table.txt diff --git a/shell-pipelines/sort-uniq-head-tail/script-03.sh b/shell-pipelines/sort-uniq-head-tail/script-03.sh index bcbaf342..349c65d3 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-03.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-03.sh @@ -8,3 +8,5 @@ set -euo pipefail # Basia London 22 9 6 # Piotr Glasgow 15 2 25 11 8 # Chandra Birmingham 12 6 + +sort -k3 -r -n scores-table.txt | head -n 3 diff --git a/shell-pipelines/sort-uniq-head-tail/script-04.sh b/shell-pipelines/sort-uniq-head-tail/script-04.sh index 65a5cfba..8ab4fc33 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-04.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-04.sh @@ -5,3 +5,5 @@ set -euo pipefail # The input for this script is the scores-table.txt file. # TODO: Write a command to output scores-table.txt, with shows the line for the player whose first score was the second highest. # Your output should be: "Piotr Glasgow 15 2 25 11 8" (without quotes). + +sort -k3,3 -n -r scores-table.txt | head -n 2 | tail -n 1 diff --git a/shell-pipelines/sort-uniq-head-tail/script-05.sh b/shell-pipelines/sort-uniq-head-tail/script-05.sh index a93cd9f9..7bba7d19 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-05.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-05.sh @@ -6,3 +6,5 @@ set -euo pipefail # TODO: Write a command to show a list of all events that have happened, without duplication. # The order they're displayed doesn't matter, but we never want to see the same event listed twice. # Your output should contain 6 lines. + +sort events.txt | uniq diff --git a/shell-pipelines/sort-uniq-head-tail/script-06.sh b/shell-pipelines/sort-uniq-head-tail/script-06.sh index 715c7ae5..d7bdc6bd 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-06.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-06.sh @@ -5,3 +5,7 @@ set -euo pipefail # The input for this script is the events.txt file. # TODO: Write a command to show how many times anyone has entered and exited. # It should be clear from your script's output that there have been 5 Entry events and 4 Exit events. + +echo " $(grep -c Entry events.txt) Entry events" + +echo " $(grep -c Exit events.txt) Exit events" diff --git a/shell-pipelines/sort-uniq-head-tail/script-07.sh b/shell-pipelines/sort-uniq-head-tail/script-07.sh index 7fd07e1f..24289605 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-07.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-07.sh @@ -6,3 +6,6 @@ set -euo pipefail # TODO: Write a command to show how many times anyone has entered and exited. # It should be clear from your script's output that there have been 5 Entry events and 4 Exit events. # The word "Event" should not appear in your script's output. +echo "Entry: $(grep -c Entry events-with-timestamps.txt)" + +echo "Exit: $(grep -c Exit events-with-timestamps.txt) " From a6b48f6c3042ebc7e5933d83aa7a33b6ad58883a Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 16:55:11 +0000 Subject: [PATCH 04/11] Use jq -r to output name without quotes --- jq/script-01.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jq/script-01.sh b/jq/script-01.sh index 95827f68..0b4ef458 100755 --- a/jq/script-01.sh +++ b/jq/script-01.sh @@ -5,3 +5,5 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the name of the person. # Your output should be exactly the string "Selma", but should not contain any quote characters. + +jq -r '.name' person.json From c6cc1f74dff4f7f6b51b668a71ac22608063650f Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 17:09:34 +0000 Subject: [PATCH 05/11] Use jq to output address fields as single comma-seperated lines --- jq/script-02.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jq/script-02.sh b/jq/script-02.sh index 21544d67..9d65238e 100755 --- a/jq/script-02.sh +++ b/jq/script-02.sh @@ -5,3 +5,5 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the address of the person, all on one line, with a comma between each line. # Your output should be exactly the string "35 Fashion Street, London, E1 6PX", but should not contain any quote characters. +# jq -r ".address" person.json +jq -r '.address | "\(.[0]), \(.[1]), \(.[2])"' person.json From 6b1801424a613989dad4a8af075b306511ff6012 Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 17:23:12 +0000 Subject: [PATCH 06/11] Use jq to output name and profession on one line separated by a comma --- jq/script-02.sh | 2 +- jq/script-03.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/jq/script-02.sh b/jq/script-02.sh index 9d65238e..01343397 100755 --- a/jq/script-02.sh +++ b/jq/script-02.sh @@ -5,5 +5,5 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the address of the person, all on one line, with a comma between each line. # Your output should be exactly the string "35 Fashion Street, London, E1 6PX", but should not contain any quote characters. -# jq -r ".address" person.json + jq -r '.address | "\(.[0]), \(.[1]), \(.[2])"' person.json diff --git a/jq/script-03.sh b/jq/script-03.sh index 3566f03b..1f8b435a 100755 --- a/jq/script-03.sh +++ b/jq/script-03.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the name of the person, then a comma, then their profession. # Your output should be exactly the string "Selma, Software Engineer", but should not contain any quote characters. +jq -r '"\(.name), \(.profession)"' person.json From 060d1e9281ebd929f6738131a32bd754dd06502b Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 17:31:04 +0000 Subject: [PATCH 07/11] Use jq to print all names in the object --- jq/script-04.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jq/script-04.sh b/jq/script-04.sh index 015997e1..bba1e296 100755 --- a/jq/script-04.sh +++ b/jq/script-04.sh @@ -6,3 +6,5 @@ set -euo pipefail # TODO: Write a command to output just the names of each player, one per line. # Your output should contain 6 lines, each with just one word on it. # Your output should not contain any quote characters. + +jq -r '.[].name' scores.json From 52899b57e725f22d0701213fd18d733d22bbfdf5 Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 17:42:20 +0000 Subject: [PATCH 08/11] Use jq to iterate and over object and print name and city --- jq/script-05.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/jq/script-05.sh b/jq/script-05.sh index 993fc9ee..ab78fbad 100755 --- a/jq/script-05.sh +++ b/jq/script-05.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores.json file. # 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. +jq -r '.[] | "\(.name) \(.city)"' scores.json From b0c21cd7a5ed1d909dedfa67c28ea18ca0c27980 Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 17:51:52 +0000 Subject: [PATCH 09/11] Use jq command to print the name and the first score --- jq/script-06.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jq/script-06.sh b/jq/script-06.sh index 8b6e74c5..76147395 100755 --- a/jq/script-06.sh +++ b/jq/script-06.sh @@ -6,3 +6,5 @@ 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" with no quotes. +jq -r '.[] | "\(.name) \(.scores[0])"' scores.json + From e9cc6d044b411eff89ce59f1b1b1b071cebc2acf Mon Sep 17 00:00:00 2001 From: ike-agu Date: Tue, 25 Nov 2025 18:22:18 +0000 Subject: [PATCH 10/11] Use jq to sum individual scores and all scores --- jq/script-06.sh | 1 - jq/script-07.sh | 1 + jq/script-08.sh | 1 + jq/script-09.sh | 1 + jq/script-10.sh | 1 + jq/script-11.sh | 2 ++ 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/jq/script-06.sh b/jq/script-06.sh index 76147395..47fee35b 100755 --- a/jq/script-06.sh +++ b/jq/script-06.sh @@ -7,4 +7,3 @@ set -euo pipefail # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 1" with no quotes. jq -r '.[] | "\(.name) \(.scores[0])"' scores.json - diff --git a/jq/script-07.sh b/jq/script-07.sh index d43f93d1..f20ab3d7 100755 --- a/jq/script-07.sh +++ b/jq/script-07.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the score from their last attempt. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 4" with no quotes. +jq -r '.[] | "\(.name) \(.scores[-1])"' scores.json diff --git a/jq/script-08.sh b/jq/script-08.sh index 6671fd1b..165e67a4 100755 --- a/jq/script-08.sh +++ b/jq/script-08.sh @@ -6,3 +6,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" with no quotes. +jq -r '.[] | "\(.name) \(.scores | length)"' scores.json diff --git a/jq/script-09.sh b/jq/script-09.sh index c2536a53..3ce4c2b7 100755 --- a/jq/script-09.sh +++ b/jq/script-09.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the total scores from all of their games added together. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 15" with no quotes. +jq -r '.[] | "\(.name) \(.scores | add)"' scores.json diff --git a/jq/script-10.sh b/jq/script-10.sh index 8e9d75f0..8b124325 100755 --- a/jq/script-10.sh +++ b/jq/script-10.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores.json file. # TODO: Write a command to output the total of adding together all players' first scores. # Your output should be exactly the number 54. +jq -r '[.[].scores[0]] | add' scores.json diff --git a/jq/script-11.sh b/jq/script-11.sh index d2337a6b..9f9708c4 100755 --- a/jq/script-11.sh +++ b/jq/script-11.sh @@ -5,3 +5,5 @@ set -euo pipefail # The input for this script is the scores.json file. # TODO: Write a command to output the total of adding together all scores from all games from all players. # Your output should be exactly the number 164. + +jq -r '[.[].scores[]] | add' scores.json From 3d11e787ff7436e5006a797c254f64c6499a769a Mon Sep 17 00:00:00 2001 From: ike-agu Date: Mon, 9 Feb 2026 23:41:07 +0000 Subject: [PATCH 11/11] Update jq to use join() so it works for any number of adress lines --- jq/script-02.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jq/script-02.sh b/jq/script-02.sh index 01343397..bfb98638 100755 --- a/jq/script-02.sh +++ b/jq/script-02.sh @@ -6,4 +6,4 @@ set -euo pipefail # TODO: Write a command to output the address of the person, all on one line, with a comma between each line. # Your output should be exactly the string "35 Fashion Street, London, E1 6PX", but should not contain any quote characters. -jq -r '.address | "\(.[0]), \(.[1]), \(.[2])"' person.json +jq -r '.address | join(", ")' person.json