From e7346d7d498640f9d2285fb6e8010bfffef46849 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:22:15 +0100 Subject: [PATCH 01/42] Wrote shell command to ouput column from a file --- individual-shell-tools/awk/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/awk/script-01.sh b/individual-shell-tools/awk/script-01.sh index 8db4390af..c251968be 100755 --- a/individual-shell-tools/awk/script-01.sh +++ b/individual-shell-tools/awk/script-01.sh @@ -2,5 +2,6 @@ set -euo pipefail +awk '{print $1}' scores-table.txt # 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. From e691d8ef5e9d8298f8eeb0616e76272143510ef8 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:23:33 +0100 Subject: [PATCH 02/42] Wrote shell command that output multiple column from a file --- individual-shell-tools/awk/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/awk/script-02.sh b/individual-shell-tools/awk/script-02.sh index 5956be9bd..fe8557ad1 100755 --- a/individual-shell-tools/awk/script-02.sh +++ b/individual-shell-tools/awk/script-02.sh @@ -2,5 +2,6 @@ set -euo pipefail +awk '{print $1,$2}' scores-table.txt # 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. From 6ae44ef933156800526bb3fe65aeb95245c1686f Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:25:25 +0100 Subject: [PATCH 03/42] Wrote command that output multiple column from a text file - name and first attempt --- individual-shell-tools/awk/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/awk/script-03.sh b/individual-shell-tools/awk/script-03.sh index af7c6e8b9..2f4511a83 100755 --- a/individual-shell-tools/awk/script-03.sh +++ b/individual-shell-tools/awk/script-03.sh @@ -2,6 +2,7 @@ set -euo pipefail +awk '{print $1,$3}' scores-table.txt # 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". From ee519ea18ff4f1574789ba12e5d261a42469837f Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:33:34 +0100 Subject: [PATCH 04/42] Wrote command with condition to output only players in london names and their last attempt --- individual-shell-tools/awk/script-04.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/awk/script-04.sh b/individual-shell-tools/awk/script-04.sh index bf15703c7..b34630ab8 100755 --- a/individual-shell-tools/awk/script-04.sh +++ b/individual-shell-tools/awk/script-04.sh @@ -2,6 +2,7 @@ set -euo pipefail +awk '$2 == "London"{print $1,$5}' scores-table.txt # 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". From 9e7547109a6f1a536219bd873e54cdad9a38ba4d Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:47:21 +0100 Subject: [PATCH 05/42] Wrote command that calculate number of times each player played and output it --- individual-shell-tools/awk/script-05.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/individual-shell-tools/awk/script-05.sh b/individual-shell-tools/awk/script-05.sh index d1680cb02..bc6095442 100755 --- a/individual-shell-tools/awk/script-05.sh +++ b/individual-shell-tools/awk/script-05.sh @@ -2,6 +2,8 @@ set -euo pipefail +awk '($3 > 0) {attempt++} ($4 > 0) {attempt++} ($5 > 0) {attempt++} ($6 > 0) {attempt++} ($7 > 0) {attempt++} {print $1,attempt} attempt=0' scores-table.txt + # 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". From 992998c14d37df7b901084ac42cb3a96099b3c2f Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:55:46 +0100 Subject: [PATCH 06/42] Wrote command that caluclate sum of all players first play and output last result --- individual-shell-tools/awk/script-06-stretch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/individual-shell-tools/awk/script-06-stretch.sh b/individual-shell-tools/awk/script-06-stretch.sh index 0201e6378..f0a714ed1 100755 --- a/individual-shell-tools/awk/script-06-stretch.sh +++ b/individual-shell-tools/awk/script-06-stretch.sh @@ -3,6 +3,6 @@ set -euo pipefail # NOTE: This is a stretch exercise - it is optional. - +awk '{total += $3} END {print total}' scores-table.txt # TODO: Write a command to output the total of adding together all players' first scores. # Your output should be exactly the number 54. From dc54f59daf11288a09c30ea17fd80b3ac87b71cc Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:00:09 +0100 Subject: [PATCH 07/42] wrote command to output the contents of the helper1 file --- individual-shell-tools/cat/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/cat/script-01.sh b/individual-shell-tools/cat/script-01.sh index c85053e0f..682b379b6 100755 --- a/individual-shell-tools/cat/script-01.sh +++ b/individual-shell-tools/cat/script-01.sh @@ -3,4 +3,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. +cat ../helper-files/helper-1.txt # The output of this command should be "Once upon a time...". From 899fa3bf3233f7bb385ab70c25d22eaa75b71632 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:02:24 +0100 Subject: [PATCH 08/42] Wrote command that output contents with multiple files using cat once --- individual-shell-tools/cat/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/cat/script-02.sh b/individual-shell-tools/cat/script-02.sh index 01bbd5eab..e0d70e235 100755 --- a/individual-shell-tools/cat/script-02.sh +++ b/individual-shell-tools/cat/script-02.sh @@ -11,3 +11,4 @@ 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/helper-1.txt" "../helper-files/helper-2.txt" "../helper-files/helper-3.txt" \ No newline at end of file From 90222f4330ed6b86c7ee9f0878fbfc21eac9ffae Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:04:11 +0100 Subject: [PATCH 09/42] Wrote command output the file content plus each line number --- individual-shell-tools/cat/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/cat/script-03.sh b/individual-shell-tools/cat/script-03.sh index 37573b0c1..e4c6d99f6 100755 --- a/individual-shell-tools/cat/script-03.sh +++ b/individual-shell-tools/cat/script-03.sh @@ -9,3 +9,4 @@ 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 -n ../helper-files/helper-3.txt \ No newline at end of file From 5032ba4c7cb0721c1ff460a96019ed7aa3dc813f Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:11:21 +0100 Subject: [PATCH 10/42] Wrote command of grep output everyline in diaglougue file --- individual-shell-tools/grep/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/grep/script-01.sh b/individual-shell-tools/grep/script-01.sh index fb05f42f2..72ed5638b 100755 --- a/individual-shell-tools/grep/script-01.sh +++ b/individual-shell-tools/grep/script-01.sh @@ -2,5 +2,6 @@ set -euo pipefail +grep "" dialogue.txt # TODO: Write a command to output every line in dialogue.txt said by the Doctor. # The output should contain 6 lines. From a4a5fbc74c0dac34bf63145af5af3ee5c4f91914 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:12:10 +0100 Subject: [PATCH 11/42] Wrote command that grep any line have the word 'Doctor' --- individual-shell-tools/grep/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/grep/script-02.sh b/individual-shell-tools/grep/script-02.sh index df6f85640..e38d0cb56 100755 --- a/individual-shell-tools/grep/script-02.sh +++ b/individual-shell-tools/grep/script-02.sh @@ -2,5 +2,6 @@ set -euo pipefail +grep -F "Doctor" dialogue.txt # 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. From 227e1555b89a357325d03e1cd0313d4ccdf56ae5 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:14:47 +0100 Subject: [PATCH 12/42] Wrote command output the number of lines in diaglogue.txt that contain the word Dcotor --- individual-shell-tools/grep/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/grep/script-03.sh b/individual-shell-tools/grep/script-03.sh index 5383fe578..6157aa201 100755 --- a/individual-shell-tools/grep/script-03.sh +++ b/individual-shell-tools/grep/script-03.sh @@ -4,3 +4,4 @@ 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. +grep -c "Doctor" dialogue.txt \ No newline at end of file From 8e3d8b725f12c269f83d73184ac3b2c759782143 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:19:33 +0100 Subject: [PATCH 13/42] Wrote command output the number of lines in diaglogue.txt that contain the word Dcotor with ignoring --- individual-shell-tools/grep/script-03.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/individual-shell-tools/grep/script-03.sh b/individual-shell-tools/grep/script-03.sh index 6157aa201..21138258a 100755 --- a/individual-shell-tools/grep/script-03.sh +++ b/individual-shell-tools/grep/script-03.sh @@ -4,4 +4,4 @@ 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. -grep -c "Doctor" dialogue.txt \ No newline at end of file +grep -ci "Doctor" dialogue.txt \ No newline at end of file From e467605926eb38c0f20ce7bb9d1e079cacccba58 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:11:52 +0100 Subject: [PATCH 14/42] Wrote command to ouput everyline that does not contain specific word regardiling the senesitive case --- individual-shell-tools/grep/script-04.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/grep/script-04.sh b/individual-shell-tools/grep/script-04.sh index 80ee04776..392ff8d8f 100755 --- a/individual-shell-tools/grep/script-04.sh +++ b/individual-shell-tools/grep/script-04.sh @@ -4,3 +4,4 @@ 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 -vi "Hello" dialogue.txt \ No newline at end of file From 745f19aaad0a8953394cc179ecda4ec3ffcaadce Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:14:29 +0100 Subject: [PATCH 15/42] Wrote command to output everyline that contain specific word as well the line before --- individual-shell-tools/grep/script-05.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/grep/script-05.sh b/individual-shell-tools/grep/script-05.sh index 1eb538185..a7e28a473 100755 --- a/individual-shell-tools/grep/script-05.sh +++ b/individual-shell-tools/grep/script-05.sh @@ -4,3 +4,4 @@ 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 -B 1 "cure" dialogue.txt \ No newline at end of file From 0465ff304c721e163c001c838097d47ba86fc37f Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:34:33 +0100 Subject: [PATCH 16/42] Wrote command that list the files and folder in directory current --- individual-shell-tools/ls/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/ls/script-01.sh b/individual-shell-tools/ls/script-01.sh index 241b62f5e..044af3619 100755 --- a/individual-shell-tools/ls/script-01.sh +++ b/individual-shell-tools/ls/script-01.sh @@ -12,4 +12,5 @@ if [[ "${script_dir}" != "$(pwd)" ]]; then fi # TODO: Write a command to list the files and folders in this directory. +ls # The output should be a list of names including child-directory, script-01.sh, script-02.sh, and more. From f168750028665648e570a14360efa903f9a0d295 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:35:25 +0100 Subject: [PATCH 17/42] Wrote command list directory files --- individual-shell-tools/ls/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/ls/script-02.sh b/individual-shell-tools/ls/script-02.sh index d0a5a10f4..5fecd71f1 100755 --- a/individual-shell-tools/ls/script-02.sh +++ b/individual-shell-tools/ls/script-02.sh @@ -3,4 +3,5 @@ set -euo pipefail # TODO: Write a command which lists all of the files in the directory named child-directory. +ls child-directory/ # The output should be a list of names: helper-1.txt, helper-2.txt, helper-3.txt. From cda966e97fb7065b2b301db5ae0e2c2a15d362fd Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:46:22 +0100 Subject: [PATCH 18/42] Wrote comand which list allfiles and folders files --- individual-shell-tools/ls/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/ls/script-03.sh b/individual-shell-tools/ls/script-03.sh index 781216d21..4ccbb560a 100755 --- a/individual-shell-tools/ls/script-03.sh +++ b/individual-shell-tools/ls/script-03.sh @@ -4,4 +4,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). +ls -R # The formatting of the output doesn't matter. From 0a823e73ae82b2dea1209431c4876294e110e1c8 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:49:59 +0100 Subject: [PATCH 19/42] Wrote command to list files by sorting recent modification --- individual-shell-tools/ls/script-04.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/individual-shell-tools/ls/script-04.sh b/individual-shell-tools/ls/script-04.sh index 72f3817b3..8b8c3f534 100755 --- a/individual-shell-tools/ls/script-04.sh +++ b/individual-shell-tools/ls/script-04.sh @@ -15,9 +15,10 @@ 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 echo "Second exercise (sorted oldest to newest):" +ls -tr child-directory # 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. From de3f8e3371b67e50be88cc46aa703569fd40da10 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:33:19 +0100 Subject: [PATCH 20/42] Answered the number systems questions --- individual-shell-tools/sed/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/individual-shell-tools/sed/script-01.sh b/individual-shell-tools/sed/script-01.sh index d592970fc..0c2fad10f 100755 --- a/individual-shell-tools/sed/script-01.sh +++ b/individual-shell-tools/sed/script-01.sh @@ -5,3 +5,4 @@ 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' input.txt From 553e161e3e17108086a594deb88069c86732b1c1 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:35:32 +0100 Subject: [PATCH 21/42] Answered the number systems questions --- number-systems/README.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/number-systems/README.md b/number-systems/README.md index 77a3bde94..3efe1280a 100644 --- a/number-systems/README.md +++ b/number-systems/README.md @@ -6,60 +6,61 @@ The goal of these exercises is for you to gain an intuition for binary numbers. Convert the decimal number 14 to binary. Answer: - +0001 0100 Convert the binary number 101101 to decimal: Answer: - +45 Which is larger: 1000 or 0111? Answer: - +1000 Which is larger: 00100 or 01011? Answer: - +01011 What is 10101 + 01010? Answer: - +11111 What is 10001 + 10001? Answer: - +100010 What's the largest number you can store with 4 bits, if you want to be able to represent the number 0? Answer: - +15 How many bits would you need in order to store the numbers between 0 and 255 inclusive? Answer: - +8 bits How many bits would you need in order to store the numbers between 0 and 3 inclusive? Answer: - +2 bits How many bits would you need in order to store the numbers between 0 and 1000 inclusive? Answer: - +10 bits How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)? Answer: - +Binary number should have at least 1 bit set to 1 Convert the decimal number 14 to hex. Answer: - +E Convert the decimal number 386 to hex. Answer: - +182 Convert the hex number 386 to decimal. Answer: - +902 Convert the hex number B to decimal. Answer: - +11 If reading the byte 0x21 as a number, what decimal number would it mean? Answer: - +33 If reading the byte 0x21 as an ASCII character, what character would it mean? Answer: - +! If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? Answer: - +dark grey If reading the bytes 0xAA00FF as an RGB colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? Answer: If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be? Answer: +(170, 0, 255) From cec0f6f66a05f6a2aae4007f27aa7319728833fa Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 29 Mar 2026 14:54:12 +0200 Subject: [PATCH 22/42] Used jq command to output person details from object on json file --- jq/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/jq/script-01.sh b/jq/script-01.sh index 95827f688..efc9479b2 100755 --- a/jq/script-01.sh +++ b/jq/script-01.sh @@ -4,4 +4,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. +jq '.name' person.json # Your output should be exactly the string "Selma", but should not contain any quote characters. From e53d98b6dd8e5a73bb1ed51d4371234de5491557 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 29 Mar 2026 15:11:29 +0200 Subject: [PATCH 23/42] jq output of array joined --- jq/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/jq/script-02.sh b/jq/script-02.sh index 21544d67b..421db5a62 100755 --- a/jq/script-02.sh +++ b/jq/script-02.sh @@ -4,4 +4,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. +jq -c '.address | join(", ")' person.json # Your output should be exactly the string "35 Fashion Street, London, E1 6PX", but should not contain any quote characters. From 06769c9a914e3b8e5d50c7d7e5b4b5a5e6181444 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 29 Mar 2026 15:19:17 +0200 Subject: [PATCH 24/42] Output name and profession in one line --- jq/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/jq/script-03.sh b/jq/script-03.sh index 3566f03ba..ad448aff3 100755 --- a/jq/script-03.sh +++ b/jq/script-03.sh @@ -4,4 +4,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, then a comma, then their profession. +jq '[.name, .profession] | join(", ")' person.json # Your output should be exactly the string "Selma, Software Engineer", but should not contain any quote characters. From d778a237a8facacbc24189ebf3f8b1c13735b841 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 29 Mar 2026 15:23:48 +0200 Subject: [PATCH 25/42] output each user on array --- jq/scores.json | 9 ++++++++- jq/script-04.sh | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jq/scores.json b/jq/scores.json index d5f62bf7a..1daea2144 100644 --- a/jq/scores.json +++ b/jq/scores.json @@ -1 +1,8 @@ -[{"name": "Ahmed", "city": "London", "scores": [1, 10, 4]}, {"name": "Basia", "city": "London", "scores": [22, 9, 6]}, {"name": "Mehmet", "city": "Birmingham", "scores": [3, 12, 17]}, {"name": "Leila", "city": "London", "scores": [1]}, {"name": "Piotr", "city": "Glasgow", "scores": [15, 2, 25, 11, 8]}, {"name": "Chandra", "city": "Birmingham", "scores": [12, 6]}] +[ + { "name": "Ahmed", "city": "London", "scores": [1, 10, 4] }, + { "name": "Basia", "city": "London", "scores": [22, 9, 6] }, + { "name": "Mehmet", "city": "Birmingham", "scores": [3, 12, 17] }, + { "name": "Leila", "city": "London", "scores": [1] }, + { "name": "Piotr", "city": "Glasgow", "scores": [15, 2, 25, 11, 8] }, + { "name": "Chandra", "city": "Birmingham", "scores": [12, 6] } +] diff --git a/jq/script-04.sh b/jq/script-04.sh index 015997e18..a3254cee2 100755 --- a/jq/script-04.sh +++ b/jq/script-04.sh @@ -4,5 +4,6 @@ set -euo pipefail # The input for this script is the scores.json file. # TODO: Write a command to output just the names of each player, one per line. +jq '.[].name' scores.json # Your output should contain 6 lines, each with just one word on it. # Your output should not contain any quote characters. From f95db5548ea87f472636794b52550db8113afd75 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:43:31 +0200 Subject: [PATCH 26/42] Output the names of files that contains at least one upper case letter --- shell-pipelines/ls-grep/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/ls-grep/script-01.sh b/shell-pipelines/ls-grep/script-01.sh index 8c7d968a2..11b640a34 100755 --- a/shell-pipelines/ls-grep/script-01.sh +++ b/shell-pipelines/ls-grep/script-01.sh @@ -3,4 +3,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. +ls sample-files | grep '[A-Z]' # Your output should contain 11 files. From a5855007047740d50c5843b3c6fac4e1db31174d Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:46:18 +0200 Subject: [PATCH 27/42] Output file name which starts with an upper case letter --- shell-pipelines/ls-grep/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/ls-grep/script-02.sh b/shell-pipelines/ls-grep/script-02.sh index 16f5f71d9..8e73df07b 100755 --- a/shell-pipelines/ls-grep/script-02.sh +++ b/shell-pipelines/ls-grep/script-02.sh @@ -3,4 +3,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. +ls sample-files | grep '^[A-Z]' # Your output should contain 10 files. From 1bf5ee1ce5cec11576bc17b557109155147ad040 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:50:41 +0200 Subject: [PATCH 28/42] output file that starts with upper case only --- shell-pipelines/ls-grep/script-03.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/ls-grep/script-03.sh b/shell-pipelines/ls-grep/script-03.sh index a302ab036..e836be84e 100755 --- a/shell-pipelines/ls-grep/script-03.sh +++ b/shell-pipelines/ls-grep/script-03.sh @@ -3,4 +3,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. +ls sample-files | grep '^[A-Z][^A-Z]*$' # Your output should contain 7 files. From 4d9525bd00c92164c3bdd69fe77f1b3f283bca99 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:54:01 +0200 Subject: [PATCH 29/42] Output count of files which start with upper case letter and doesn't contain any other upper case letter --- shell-pipelines/ls-grep/script-04.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/ls-grep/script-04.sh b/shell-pipelines/ls-grep/script-04.sh index c000b7e3b..5ae6ab961 100755 --- a/shell-pipelines/ls-grep/script-04.sh +++ b/shell-pipelines/ls-grep/script-04.sh @@ -3,4 +3,5 @@ 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. +ls sample-files | grep -c '^[A-Z][^A-Z]*$' # Your output should be the number 7. From d56a3e0099cdfda9bc5d9be86da03b3a60098b10 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:56:55 +0200 Subject: [PATCH 30/42] Sorting file data by person's name --- shell-pipelines/sort-uniq-head-tail/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-01.sh b/shell-pipelines/sort-uniq-head-tail/script-01.sh index 171e1f989..c43bc7e78 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-01.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-01.sh @@ -4,4 +4,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 name. +sort scores-table.txt # 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". From 3a4cb7b9cbc26e8fc51b8c0e6c53e40e4d73d099 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:01:47 +0200 Subject: [PATCH 31/42] output text changed caractere with tr shell scripting --- shell-pipelines/tr/script-01.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/tr/script-01.sh b/shell-pipelines/tr/script-01.sh index 8bb0211e9..75c3ed25f 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 '!' '.' From a69e7b3659d90a9d0add3cb4557873baaa5d9ca6 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:04:27 +0200 Subject: [PATCH 32/42] Swapper the uppercase letter to lower and the opposite --- shell-pipelines/tr/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/tr/script-02.sh b/shell-pipelines/tr/script-02.sh index cf3a503a2..261497f1b 100755 --- a/shell-pipelines/tr/script-02.sh +++ b/shell-pipelines/tr/script-02.sh @@ -7,3 +7,4 @@ 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 'Z' 'z' | tr 'Y' 'y' | tr 'z' 'Z' | tr 'y' 'Y' From ebc28b467e9aff7673a6413c3dce7a55f3f45647 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:17:07 +0200 Subject: [PATCH 33/42] Output scores with lines sorted by the person first score --- shell-pipelines/sort-uniq-head-tail/script-02.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-02.sh b/shell-pipelines/sort-uniq-head-tail/script-02.sh index 29c3c2524..b65564747 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 -k3 -nr scores-table.txt \ No newline at end of file From 88bb3ce582af1a989309e340c83069c64778e4c8 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:18:57 +0200 Subject: [PATCH 34/42] output first 3 lines highest score players --- shell-pipelines/sort-uniq-head-tail/script-03.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-03.sh b/shell-pipelines/sort-uniq-head-tail/script-03.sh index bcbaf3420..e0576a164 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 -k3nr scores-table.txt | head -n 3 \ No newline at end of file From 9ef01321dcc6ba2d40e2eab637425df2f95f3859 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:22:29 +0200 Subject: [PATCH 35/42] output second high player score --- shell-pipelines/sort-uniq-head-tail/script-04.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-04.sh b/shell-pipelines/sort-uniq-head-tail/script-04.sh index 65a5cfba8..344612f86 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 -k3nr scores-table.txt | head -n 2 | tail -n 1 From 1edd09d655d850de7056c6c52b7fc5b52092f5fd Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:26:46 +0200 Subject: [PATCH 36/42] sorted duplicated event --- shell-pipelines/sort-uniq-head-tail/script-05.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-05.sh b/shell-pipelines/sort-uniq-head-tail/script-05.sh index a93cd9f9d..6bfeb53c2 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 -u events.txt \ No newline at end of file From 445bb2eef17d071c8a5b752da3c8de3cbc845e4d Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 15:56:10 +0200 Subject: [PATCH 37/42] output by group --- shell-pipelines/sort-uniq-head-tail/script-06.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-06.sh b/shell-pipelines/sort-uniq-head-tail/script-06.sh index 715c7ae5c..a1f6faf26 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-06.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-06.sh @@ -5,3 +5,4 @@ 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. +sort events.txt | uniq --group From a715e1ff21652fb8177fcce8a03050b61d58e858 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 5 Apr 2026 15:57:03 +0200 Subject: [PATCH 38/42] output by group --- shell-pipelines/sort-uniq-head-tail/script-07.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell-pipelines/sort-uniq-head-tail/script-07.sh b/shell-pipelines/sort-uniq-head-tail/script-07.sh index 7fd07e1ff..91442b64a 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. +sort events.txt | uniq --group \ No newline at end of file From 4a2521081be4a84044a70e32cf703f95cd76a3dc Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 12 Apr 2026 16:25:52 +0200 Subject: [PATCH 39/42] Created node function that read a file and output the file content on terminal --- implement-shell-tools/cat/cat.js | 11 +++++++++ implement-shell-tools/cat/package-lock.json | 25 +++++++++++++++++++++ implement-shell-tools/cat/package.json | 16 +++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 implement-shell-tools/cat/cat.js create mode 100644 implement-shell-tools/cat/package-lock.json create mode 100644 implement-shell-tools/cat/package.json diff --git a/implement-shell-tools/cat/cat.js b/implement-shell-tools/cat/cat.js new file mode 100644 index 000000000..e2cef8f0d --- /dev/null +++ b/implement-shell-tools/cat/cat.js @@ -0,0 +1,11 @@ +import { program } from 'commander' +import process from 'process' +import fs from 'fs' + +const argv = process.argv[2] +const data = fs.readFileSync(`sample-files/${argv}`, 'utf-8') +program + .command('cat') + .description('Output file content') + .option('-a, --all', "show all users' processes") + .action(console.log(data)) diff --git a/implement-shell-tools/cat/package-lock.json b/implement-shell-tools/cat/package-lock.json new file mode 100644 index 000000000..737542646 --- /dev/null +++ b/implement-shell-tools/cat/package-lock.json @@ -0,0 +1,25 @@ +{ + "name": "cat", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "cat", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "commander": "^14.0.3" + } + }, + "node_modules/commander": { + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz", + "integrity": "sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==", + "license": "MIT", + "engines": { + "node": ">=20" + } + } + } +} diff --git a/implement-shell-tools/cat/package.json b/implement-shell-tools/cat/package.json new file mode 100644 index 000000000..5d63dc09d --- /dev/null +++ b/implement-shell-tools/cat/package.json @@ -0,0 +1,16 @@ +{ + "name": "cat", + "version": "1.0.0", + "description": "You should already be familiar with the `cat` command line tool.", + "main": "cat.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "module", + "dependencies": { + "commander": "^14.0.3" + } +} From 820efc8da7efe68985b354f9bf055751c095ff07 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 12 Apr 2026 16:52:47 +0200 Subject: [PATCH 40/42] Implemenet option to output all content, output each line with line number or output total line none empty --- implement-shell-tools/cat/cat.js | 34 +++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/implement-shell-tools/cat/cat.js b/implement-shell-tools/cat/cat.js index e2cef8f0d..dcd7e09ba 100644 --- a/implement-shell-tools/cat/cat.js +++ b/implement-shell-tools/cat/cat.js @@ -2,10 +2,34 @@ import { program } from 'commander' import process from 'process' import fs from 'fs' -const argv = process.argv[2] -const data = fs.readFileSync(`sample-files/${argv}`, 'utf-8') +// const argv = process.argv[4] +// const data = fs.readFileSync(`sample-files/${argv}`, 'utf-8') + program - .command('cat') + .command('cat ') .description('Output file content') - .option('-a, --all', "show all users' processes") - .action(console.log(data)) + .option('-a, --all', 'Output all content') + .option('-n, --line', 'Output each line with number') + .option('-b, --nonempty', 'Output total lines not empty') + .action((file, options) => { + const data = fs.readFileSync(`sample-files/${file}`, 'utf-8').split('\n') + if (options.all) { + console.log(data.join()) + } + if (options.line) { + for (let i = 0; i < data.length; i++) { + console.log(`${i} - ${data[i]}`) + } + } + if (options.nonempty) { + let totalline = 0 + data.forEach((line) => { + if (line.length != 0) { + totalline++ + } + }) + console.log(totalline) + } + }) + +program.parse() From 20f8448b9726fabf9fe69fed03d1e299d7e7b7a0 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 12 Apr 2026 22:44:13 +0200 Subject: [PATCH 41/42] Implemented node that act the same as script shelling ls --- implement-shell-tools/ls/ls.js | 22 +++++++++++++++++++ implement-shell-tools/ls/package-lock.json | 25 ++++++++++++++++++++++ implement-shell-tools/ls/package.json | 16 ++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 implement-shell-tools/ls/ls.js create mode 100644 implement-shell-tools/ls/package-lock.json create mode 100644 implement-shell-tools/ls/package.json diff --git a/implement-shell-tools/ls/ls.js b/implement-shell-tools/ls/ls.js new file mode 100644 index 000000000..c5f440ae2 --- /dev/null +++ b/implement-shell-tools/ls/ls.js @@ -0,0 +1,22 @@ +import { program } from 'commander' +import process from 'process' +import fs from 'fs' +program + .command('ls') + .description('Output available files on directory') + .option('-a, --all', 'Output all files') + .option('-1, --line', 'List one file per line') + .action((options) => { + const contents = fs.readdirSync(process.cwd(), { withFileTypes: true }) + + if (options.all) { + contents.forEach((content) => { + console.log(content.name) + }) + } + if (options.line) { + console.log(contents[0].name) + } + }) + +program.parse() diff --git a/implement-shell-tools/ls/package-lock.json b/implement-shell-tools/ls/package-lock.json new file mode 100644 index 000000000..74bc88d5b --- /dev/null +++ b/implement-shell-tools/ls/package-lock.json @@ -0,0 +1,25 @@ +{ + "name": "ls", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ls", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "commander": "^14.0.3" + } + }, + "node_modules/commander": { + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz", + "integrity": "sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==", + "license": "MIT", + "engines": { + "node": ">=20" + } + } + } +} diff --git a/implement-shell-tools/ls/package.json b/implement-shell-tools/ls/package.json new file mode 100644 index 000000000..43e0a50d8 --- /dev/null +++ b/implement-shell-tools/ls/package.json @@ -0,0 +1,16 @@ +{ + "name": "ls", + "version": "1.0.0", + "description": "You should already be familiar with the `ls` command line tool.", + "main": "ls.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "module", + "dependencies": { + "commander": "^14.0.3" + } +} From ab2a350619623d2925136c9dc4c844bac3851347 Mon Sep 17 00:00:00 2001 From: Iheb Hamdi <67348203+hamdiheb@users.noreply.github.com> Date: Sun, 12 Apr 2026 23:27:49 +0200 Subject: [PATCH 42/42] Implement node function that works as script shell wc command --- implement-shell-tools/wc/package-lock.json | 90 ++++++++++++++++++++++ implement-shell-tools/wc/package.json | 17 ++++ implement-shell-tools/wc/wc.js | 28 +++++++ 3 files changed, 135 insertions(+) create mode 100644 implement-shell-tools/wc/package-lock.json create mode 100644 implement-shell-tools/wc/package.json create mode 100644 implement-shell-tools/wc/wc.js diff --git a/implement-shell-tools/wc/package-lock.json b/implement-shell-tools/wc/package-lock.json new file mode 100644 index 000000000..c659e11e8 --- /dev/null +++ b/implement-shell-tools/wc/package-lock.json @@ -0,0 +1,90 @@ +{ + "name": "wc", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "wc", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "buffer": "^6.0.3", + "commander": "^14.0.3" + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/commander": { + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz", + "integrity": "sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + } + } +} diff --git a/implement-shell-tools/wc/package.json b/implement-shell-tools/wc/package.json new file mode 100644 index 000000000..85fa9a7b4 --- /dev/null +++ b/implement-shell-tools/wc/package.json @@ -0,0 +1,17 @@ +{ + "name": "wc", + "version": "1.0.0", + "description": "You should already be familiar with the `wc` command line tool.", + "main": "wc.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "module", + "dependencies": { + "buffer": "^6.0.3", + "commander": "^14.0.3" + } +} diff --git a/implement-shell-tools/wc/wc.js b/implement-shell-tools/wc/wc.js new file mode 100644 index 000000000..d5176846d --- /dev/null +++ b/implement-shell-tools/wc/wc.js @@ -0,0 +1,28 @@ +import { program } from 'commander' +import fs from 'fs' +import { Buffer } from 'buffer' +import process from 'process' +program + .command('wc ') + .description('File word counts') + .option('-l, --line', 'print the newline counts') + .option('-w, --count', 'print the word counts') + .option('-c, --bytes', 'print the bytes counts') + .action((file, options) => { + const content = fs.readFileSync(`sample-files/${file}`, 'utf-8') + if (options.line) { + console.log(content.split('\n').length) + } + if (options.bytes) { + console.log(Buffer.from(content).toString('hex')) + } + if (options.count) { + console.log(content.split(' ').length) + } + if (options.line && file == '*') { + const files = fs.readdirSync('sample-files/', { withFileTypes: true }) + console.log(files) + } + }) + +program.parse()