From 2238124f3fc32814ea8096aeeda6c60625836cc1 Mon Sep 17 00:00:00 2001 From: Sara Tahir Date: Thu, 13 Nov 2025 11:44:18 +0000 Subject: [PATCH 1/4] Answering all exercises for ls-grep folder --- shell-pipelines/ls-grep/script-01.sh | 1 + shell-pipelines/ls-grep/script-02.sh | 1 + shell-pipelines/ls-grep/script-03.sh | 3 +++ shell-pipelines/ls-grep/script-04.sh | 1 + 4 files changed, 6 insertions(+) diff --git a/shell-pipelines/ls-grep/script-01.sh b/shell-pipelines/ls-grep/script-01.sh index 8c7d968a2..ed720c3b3 100755 --- a/shell-pipelines/ls-grep/script-01.sh +++ b/shell-pipelines/ls-grep/script-01.sh @@ -4,3 +4,4 @@ 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 16f5f71d9..7d476a936 100755 --- a/shell-pipelines/ls-grep/script-02.sh +++ b/shell-pipelines/ls-grep/script-02.sh @@ -4,3 +4,4 @@ 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]' \ No newline at end of file diff --git a/shell-pipelines/ls-grep/script-03.sh b/shell-pipelines/ls-grep/script-03.sh index a302ab036..2c5148a78 100755 --- a/shell-pipelines/ls-grep/script-03.sh +++ b/shell-pipelines/ls-grep/script-03.sh @@ -4,3 +4,6 @@ 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. +ls sample-files/| grep '^[A-Z][^A-Z]*$' + +# [^A-Z]*S A character that is not an uppercase letter ^ inside brackets means negation, * shows zero occurrences of it and $ ensures we are matching the whole file name \ No newline at end of file diff --git a/shell-pipelines/ls-grep/script-04.sh b/shell-pipelines/ls-grep/script-04.sh index c000b7e3b..b5e25037c 100755 --- a/shell-pipelines/ls-grep/script-04.sh +++ b/shell-pipelines/ls-grep/script-04.sh @@ -4,3 +4,4 @@ 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 -c '^[A-Z][^A-Z]*$' \ No newline at end of file From e9a5633e785ef4c60a3ad1e163298b837c95f2e1 Mon Sep 17 00:00:00 2001 From: Sara Tahir Date: Thu, 13 Nov 2025 12:04:56 +0000 Subject: [PATCH 2/4] Solving Exercises in tr folder --- shell-pipelines/tr/script-01.sh | 1 + shell-pipelines/tr/script-02.sh | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/shell-pipelines/tr/script-01.sh b/shell-pipelines/tr/script-01.sh index 8bb0211e9..6bd4576aa 100755 --- a/shell-pipelines/tr/script-01.sh +++ b/shell-pipelines/tr/script-01.sh @@ -6,3 +6,4 @@ 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 '!' '.' \ No newline at end of file diff --git a/shell-pipelines/tr/script-02.sh b/shell-pipelines/tr/script-02.sh index cf3a503a2..21b859008 100755 --- a/shell-pipelines/tr/script-02.sh +++ b/shell-pipelines/tr/script-02.sh @@ -7,3 +7,8 @@ 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' + +# or we can do it this way where the tr command reads input from text.txt file and does the operation on the input + +tr 'YyZz' 'ZzYy' < text.txt \ No newline at end of file From 43af1b8f49b90c0af0989b52ed9101ea8b02b061 Mon Sep 17 00:00:00 2001 From: Sara Tahir Date: Thu, 13 Nov 2025 13:01:42 +0000 Subject: [PATCH 3/4] Answering all questions for head,tail,sort,uniq folder --- shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt | 2 +- shell-pipelines/sort-uniq-head-tail/script-01.sh | 1 + shell-pipelines/sort-uniq-head-tail/script-02.sh | 1 + shell-pipelines/sort-uniq-head-tail/script-03.sh | 2 ++ shell-pipelines/sort-uniq-head-tail/script-04.sh | 1 + shell-pipelines/sort-uniq-head-tail/script-05.sh | 1 + shell-pipelines/sort-uniq-head-tail/script-06.sh | 3 ++- shell-pipelines/sort-uniq-head-tail/script-07.sh | 1 + 8 files changed, 10 insertions(+), 2 deletions(-) diff --git a/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt b/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt index f11a3c71d..cc500dcd1 100644 --- a/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt +++ b/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt @@ -1,4 +1,4 @@ -Date Time Event Name +taDate Time Event Name 2024-11-26 04:00 Entry Sally 2024-11-26 05:12 Entry German 2024-11-26 06:37 Exit German diff --git a/shell-pipelines/sort-uniq-head-tail/script-01.sh b/shell-pipelines/sort-uniq-head-tail/script-01.sh index 171e1f989..6149bb06b 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 -k1,1 scores-table.txt \ No newline at end of file diff --git a/shell-pipelines/sort-uniq-head-tail/script-02.sh b/shell-pipelines/sort-uniq-head-tail/script-02.sh index 29c3c2524..4e5102057 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-02.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-02.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 first score, descending. # The first line of your output should be "Basia London 22 9 6" (with no quotes). +sort -n -k3,3 -r scores-table.txt \ No newline at end of file diff --git a/shell-pipelines/sort-uniq-head-tail/script-03.sh b/shell-pipelines/sort-uniq-head-tail/script-03.sh index bcbaf3420..91c8b7fa4 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 -n -r -k3,3 scores-table.txt| head -3 + \ No newline at end of file diff --git a/shell-pipelines/sort-uniq-head-tail/script-04.sh b/shell-pipelines/sort-uniq-head-tail/script-04.sh index 65a5cfba8..fe1d44381 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-04.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-04.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 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 -nr -k3,3 scores-table.txt | head -2 | tail -1 \ No newline at end of file diff --git a/shell-pipelines/sort-uniq-head-tail/script-05.sh b/shell-pipelines/sort-uniq-head-tail/script-05.sh index a93cd9f9d..e25cf7242 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-05.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-05.sh @@ -6,3 +6,4 @@ 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 \ No newline at end of file diff --git a/shell-pipelines/sort-uniq-head-tail/script-06.sh b/shell-pipelines/sort-uniq-head-tail/script-06.sh index 715c7ae5c..9d56e56f4 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-06.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-06.sh @@ -1,7 +1,8 @@ -#!/bin/bash +awk#!/bin/bash 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. +awk '{print $1}' events.txt | sort | uniq -c \ No newline at end of file diff --git a/shell-pipelines/sort-uniq-head-tail/script-07.sh b/shell-pipelines/sort-uniq-head-tail/script-07.sh index 7fd07e1ff..6d5edc605 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-07.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-07.sh @@ -6,3 +6,4 @@ 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. +tail -n +2 events-with-timestamps.txt | awk '{print $3}'| sort | uniq -c \ No newline at end of file From 095c9308894166db1d23bd1de9e7f940dd3b06e6 Mon Sep 17 00:00:00 2001 From: Sara Tahir Date: Thu, 13 Nov 2025 13:03:20 +0000 Subject: [PATCH 4/4] fixing typos --- shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt | 2 +- shell-pipelines/sort-uniq-head-tail/script-06.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt b/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt index cc500dcd1..f11a3c71d 100644 --- a/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt +++ b/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt @@ -1,4 +1,4 @@ -taDate Time Event Name +Date Time Event Name 2024-11-26 04:00 Entry Sally 2024-11-26 05:12 Entry German 2024-11-26 06:37 Exit German diff --git a/shell-pipelines/sort-uniq-head-tail/script-06.sh b/shell-pipelines/sort-uniq-head-tail/script-06.sh index 9d56e56f4..609c2f858 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-06.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-06.sh @@ -1,4 +1,4 @@ -awk#!/bin/bash +#!/bin/bash set -euo pipefail