diff --git a/individual-shell-tools/README.md b/individual-shell-tools/README.md new file mode 100644 index 0000000..c5ace3a --- /dev/null +++ b/individual-shell-tools/README.md @@ -0,0 +1,24 @@ +# Individual shell tools exercises + +This folder contains exercises to help you get to know individual shell tools. + +Each folder is named after one tool, and contains exercises to practice using it. + +Each folder contains a number of scripts named `script-??.sh` as well as some files that are used by the scripts. You should look in the scripts one at a time and understand what you need to fix. + +When a script is complete, move on to the next script. + +When a folder is complete, move on to the next folder. + +Before running a script you should `cd` into the directory it's in. +You should write all of your scripts assuming they're running inside the directory they're saved in. + +Some folders contain a README.md explaining more information, others do not. + +We recommend approaching the tools in this order: +1. `ls` +2. `cat` +3. `wc` +4. `grep` +5. `sed` +6. `awk` diff --git a/individual-shell-tools/awk/README.md b/individual-shell-tools/awk/README.md new file mode 100644 index 0000000..95b003e --- /dev/null +++ b/individual-shell-tools/awk/README.md @@ -0,0 +1,9 @@ +scores-table.txt contains structured information. + +Each line contains information about one player in a game. +On each line, first is the player's name. +Then the city they're in. +Then a variable number of scores - one for each time they've played the game. +Each entry on a line is separated by a single space character. + +All exercises in this directory operate on the data in scores-table.txt. diff --git a/individual-shell-tools/awk/scores-table.txt b/individual-shell-tools/awk/scores-table.txt new file mode 100644 index 0000000..921ee6c --- /dev/null +++ b/individual-shell-tools/awk/scores-table.txt @@ -0,0 +1,6 @@ +Ahmed London 1 10 4 +Basia London 22 9 6 +Mehmet Birmingham 3 12 17 +Leila London 1 +Piotr Glasgow 15 2 25 11 8 +Chandra Birmingham 12 6 diff --git a/individual-shell-tools/awk/script-01.sh b/individual-shell-tools/awk/script-01.sh new file mode 100755 index 0000000..8db4390 --- /dev/null +++ b/individual-shell-tools/awk/script-01.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/awk/script-02.sh b/individual-shell-tools/awk/script-02.sh new file mode 100755 index 0000000..5956be9 --- /dev/null +++ b/individual-shell-tools/awk/script-02.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/awk/script-03.sh b/individual-shell-tools/awk/script-03.sh new file mode 100755 index 0000000..af7c6e8 --- /dev/null +++ b/individual-shell-tools/awk/script-03.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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". diff --git a/individual-shell-tools/awk/script-04.sh b/individual-shell-tools/awk/script-04.sh new file mode 100755 index 0000000..bf15703 --- /dev/null +++ b/individual-shell-tools/awk/script-04.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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". diff --git a/individual-shell-tools/awk/script-05.sh b/individual-shell-tools/awk/script-05.sh new file mode 100755 index 0000000..d1680cb --- /dev/null +++ b/individual-shell-tools/awk/script-05.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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". diff --git a/individual-shell-tools/awk/script-06-stretch.sh b/individual-shell-tools/awk/script-06-stretch.sh new file mode 100755 index 0000000..0201e63 --- /dev/null +++ b/individual-shell-tools/awk/script-06-stretch.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +# NOTE: This is a stretch exercise - it is optional. + +# TODO: Write a command to output the total of adding together all players' first scores. +# Your output should be exactly the number 54. diff --git a/individual-shell-tools/awk/script-07-stretch.sh b/individual-shell-tools/awk/script-07-stretch.sh new file mode 100755 index 0000000..3f71558 --- /dev/null +++ b/individual-shell-tools/awk/script-07-stretch.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -euo pipefail + +# NOTE: This is a stretch exercise - it is optional. + +# 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" diff --git a/individual-shell-tools/cat/script-01.sh b/individual-shell-tools/cat/script-01.sh new file mode 100755 index 0000000..c85053e --- /dev/null +++ b/individual-shell-tools/cat/script-01.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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...". diff --git a/individual-shell-tools/cat/script-02.sh b/individual-shell-tools/cat/script-02.sh new file mode 100755 index 0000000..01bbd5e --- /dev/null +++ b/individual-shell-tools/cat/script-02.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output the contents of all of the files inside the helper-files directory to the terminal. +# Make sure you are only calling `cat` once. +# +# The output of this command should be: +# Once upon a time... +# There was a house made of gingerbread. +# It looked delicious. +# I was tempted to take a bite of it. +# But this seemed like a bad idea... diff --git a/individual-shell-tools/cat/script-03.sh b/individual-shell-tools/cat/script-03.sh new file mode 100755 index 0000000..37573b0 --- /dev/null +++ b/individual-shell-tools/cat/script-03.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output the contents of the file `helper-3.txt` inside the helper-files directory to the terminal. +# This time, we also want to see the line numbers in the output. +# +# The output of this command should be something like: +# 1 It looked delicious. +# 2 I was tempted to take a bite of it. +# 3 But this seemed like a bad idea... diff --git a/individual-shell-tools/cat/script-04-stretch.sh b/individual-shell-tools/cat/script-04-stretch.sh new file mode 100755 index 0000000..00fe3c4 --- /dev/null +++ b/individual-shell-tools/cat/script-04-stretch.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail + +# NOTE: This is a stretch exercise - it is optional. + +# TODO: Write a command to output the contents of all of the files in the helper-files directory to the terminal. +# We also want to see the line numbers in the output, but we want line numbers not to reset at the start of each file. +# +# The output of this command should be something like: +# 1 Once upon a time... +# 2 There was a house made of gingerbread. +# 3 It looked delicious. +# 4 I was tempted to take a bite of it. +# 5 But this seemed like a bad idea... diff --git a/individual-shell-tools/grep/dialogue-2.txt b/individual-shell-tools/grep/dialogue-2.txt new file mode 100644 index 0000000..db93931 --- /dev/null +++ b/individual-shell-tools/grep/dialogue-2.txt @@ -0,0 +1,4 @@ +Doctor: Hello +Patient: Hello Doctor +Patient: Thank you so much for your help last week +Doctor: No problem! diff --git a/individual-shell-tools/grep/dialogue-3.txt b/individual-shell-tools/grep/dialogue-3.txt new file mode 100644 index 0000000..848826a --- /dev/null +++ b/individual-shell-tools/grep/dialogue-3.txt @@ -0,0 +1,3 @@ +Patient: That doctor is so nice! +Spouse: I'm glad he could help. +Patient: Me too! \ No newline at end of file diff --git a/individual-shell-tools/grep/dialogue.txt b/individual-shell-tools/grep/dialogue.txt new file mode 100644 index 0000000..dddc5e5 --- /dev/null +++ b/individual-shell-tools/grep/dialogue.txt @@ -0,0 +1,15 @@ +Doctor: Hello +Patient: Hello Doctor +Doctor: What's wrong today? +Patient: Hello, I can't stop saying hello +Doctor: That sounds frustrating. When did this start? +Patient: Hello, about two days ago. +Doctor: Say "Hi". +Patient: Hi +Doctor: You didn't say hello +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! diff --git a/individual-shell-tools/grep/script-01.sh b/individual-shell-tools/grep/script-01.sh new file mode 100755 index 0000000..fb05f42 --- /dev/null +++ b/individual-shell-tools/grep/script-01.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output every line in dialogue.txt said by the Doctor. +# The output should contain 6 lines. diff --git a/individual-shell-tools/grep/script-02.sh b/individual-shell-tools/grep/script-02.sh new file mode 100755 index 0000000..df6f856 --- /dev/null +++ b/individual-shell-tools/grep/script-02.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/grep/script-03.sh b/individual-shell-tools/grep/script-03.sh new file mode 100755 index 0000000..5383fe5 --- /dev/null +++ b/individual-shell-tools/grep/script-03.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/grep/script-04.sh b/individual-shell-tools/grep/script-04.sh new file mode 100755 index 0000000..80ee047 --- /dev/null +++ b/individual-shell-tools/grep/script-04.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/grep/script-05.sh b/individual-shell-tools/grep/script-05.sh new file mode 100755 index 0000000..1eb5381 --- /dev/null +++ b/individual-shell-tools/grep/script-05.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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). diff --git a/individual-shell-tools/grep/script-06.sh b/individual-shell-tools/grep/script-06.sh new file mode 100755 index 0000000..5670e3b --- /dev/null +++ b/individual-shell-tools/grep/script-06.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/grep/script-07.sh b/individual-shell-tools/grep/script-07.sh new file mode 100755 index 0000000..9670eba --- /dev/null +++ b/individual-shell-tools/grep/script-07.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/helper-files/helper-1.txt b/individual-shell-tools/helper-files/helper-1.txt new file mode 100644 index 0000000..ed7bf7d --- /dev/null +++ b/individual-shell-tools/helper-files/helper-1.txt @@ -0,0 +1 @@ +Once upon a time... diff --git a/individual-shell-tools/helper-files/helper-2.txt b/individual-shell-tools/helper-files/helper-2.txt new file mode 100644 index 0000000..c2b8f0d --- /dev/null +++ b/individual-shell-tools/helper-files/helper-2.txt @@ -0,0 +1 @@ +There was a house made of gingerbread. diff --git a/individual-shell-tools/helper-files/helper-3.txt b/individual-shell-tools/helper-files/helper-3.txt new file mode 100644 index 0000000..d2a54db --- /dev/null +++ b/individual-shell-tools/helper-files/helper-3.txt @@ -0,0 +1,3 @@ +It looked delicious. +I was tempted to take a bite of it. +But this seemed like a bad idea... diff --git a/individual-shell-tools/ls/child-directory/helper-1.txt b/individual-shell-tools/ls/child-directory/helper-1.txt new file mode 100644 index 0000000..ed7bf7d --- /dev/null +++ b/individual-shell-tools/ls/child-directory/helper-1.txt @@ -0,0 +1 @@ +Once upon a time... diff --git a/individual-shell-tools/ls/child-directory/helper-2.txt b/individual-shell-tools/ls/child-directory/helper-2.txt new file mode 100644 index 0000000..c2b8f0d --- /dev/null +++ b/individual-shell-tools/ls/child-directory/helper-2.txt @@ -0,0 +1 @@ +There was a house made of gingerbread. diff --git a/individual-shell-tools/ls/child-directory/helper-3.txt b/individual-shell-tools/ls/child-directory/helper-3.txt new file mode 100644 index 0000000..d2a54db --- /dev/null +++ b/individual-shell-tools/ls/child-directory/helper-3.txt @@ -0,0 +1,3 @@ +It looked delicious. +I was tempted to take a bite of it. +But this seemed like a bad idea... diff --git a/individual-shell-tools/ls/script-01.sh b/individual-shell-tools/ls/script-01.sh new file mode 100755 index 0000000..241b62f --- /dev/null +++ b/individual-shell-tools/ls/script-01.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail + +# Do not change this part of the script - only change after the TODO comment. + +script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +if [[ "${script_dir}" != "$(pwd)" ]]; then + echo >&2 "ERROR: You haven't cd'd into the correct directory." + echo >&2 "For each exercise, you should cd to the directory containing the script before running it." + exit 1 +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. diff --git a/individual-shell-tools/ls/script-02.sh b/individual-shell-tools/ls/script-02.sh new file mode 100755 index 0000000..d0a5a10 --- /dev/null +++ b/individual-shell-tools/ls/script-02.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/ls/script-03.sh b/individual-shell-tools/ls/script-03.sh new file mode 100755 index 0000000..781216d --- /dev/null +++ b/individual-shell-tools/ls/script-03.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/ls/script-04.sh b/individual-shell-tools/ls/script-04.sh new file mode 100755 index 0000000..72f3817 --- /dev/null +++ b/individual-shell-tools/ls/script-04.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -euo pipefail + +# Do not change this part of the script - only change after the TODO comment. + +script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +touch "${script_dir}/child-directory/helper-2.txt" +sleep 1 +touch "${script_dir}/child-directory/helper-1.txt" +sleep 1 +touch "${script_dir}/child-directory/helper-3.txt" + +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. + + +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. diff --git a/individual-shell-tools/sed/input.txt b/individual-shell-tools/sed/input.txt new file mode 100644 index 0000000..852fa15 --- /dev/null +++ b/individual-shell-tools/sed/input.txt @@ -0,0 +1,11 @@ +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. diff --git a/individual-shell-tools/sed/script-01.sh b/individual-shell-tools/sed/script-01.sh new file mode 100755 index 0000000..27b95c1 --- /dev/null +++ b/individual-shell-tools/sed/script-01.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output input.txt with all occurrences of the letter `s` replaced with `S`. +# The output should contain 11 lines. +# The first line of the output should be: "ThiS iS a Sample file for experimenting with Sed.". diff --git a/individual-shell-tools/sed/script-02.sh b/individual-shell-tools/sed/script-02.sh new file mode 100755 index 0000000..abdd64d --- /dev/null +++ b/individual-shell-tools/sed/script-02.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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". diff --git a/individual-shell-tools/sed/script-03.sh b/individual-shell-tools/sed/script-03.sh new file mode 100755 index 0000000..dd284a2 --- /dev/null +++ b/individual-shell-tools/sed/script-03.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output input.txt removing any line which contains a number. +# The output should contain 6 lines. diff --git a/individual-shell-tools/sed/script-04.sh b/individual-shell-tools/sed/script-04.sh new file mode 100755 index 0000000..0052ac6 --- /dev/null +++ b/individual-shell-tools/sed/script-04.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/sed/script-05.sh b/individual-shell-tools/sed/script-05.sh new file mode 100755 index 0000000..2dcc91a --- /dev/null +++ b/individual-shell-tools/sed/script-05.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output input.txt with one change: +# 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. diff --git a/individual-shell-tools/sed/script-06.sh b/individual-shell-tools/sed/script-06.sh new file mode 100755 index 0000000..0b93901 --- /dev/null +++ b/individual-shell-tools/sed/script-06.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output input.txt with one fix: +# If a comma in input.txt is not followed by a space, add a space after. +# If there is already a space after a comma, do not add an additional space. +# 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.". diff --git a/individual-shell-tools/wc/script-01.sh b/individual-shell-tools/wc/script-01.sh new file mode 100755 index 0000000..c9dd6e5 --- /dev/null +++ b/individual-shell-tools/wc/script-01.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/wc/script-02.sh b/individual-shell-tools/wc/script-02.sh new file mode 100755 index 0000000..8feeb1a --- /dev/null +++ b/individual-shell-tools/wc/script-02.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/individual-shell-tools/wc/script-03.sh b/individual-shell-tools/wc/script-03.sh new file mode 100755 index 0000000..6b2e9d3 --- /dev/null +++ b/individual-shell-tools/wc/script-03.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +# TODO: Write a command to output the number of lines, words, and characters in all of the files inside the helper-files directory. +# The output should be something like: +# 1 4 20 ../helper-files/helper-1.txt +# 1 7 39 ../helper-files/helper-2.txt +# 3 19 92 ../helper-files/helper-3.txt +# 5 30 151 total diff --git a/jq/README.md b/jq/README.md new file mode 100644 index 0000000..7e60485 --- /dev/null +++ b/jq/README.md @@ -0,0 +1,21 @@ +Different scripts in this folder use different data files. + +Many of the exercises in this folder are the same tasks as were done in the `awk` exercises, but using differently formatted data. + +## person.json + +`person.json` contains structured information. + +It contains data in the JSON format. +It contains one object. + +## scores.json + +`scores.json` contains structured information. + +It contains data in the JSON format. +It contains an array of objects. +Each object contains information about one player in a game. +The objects contain the fields name, city, and scores. +Name and city are strings. +Scores is an array of scores as numbers - one for each time they've played the game. diff --git a/jq/person.json b/jq/person.json new file mode 100644 index 0000000..3d3bfb1 --- /dev/null +++ b/jq/person.json @@ -0,0 +1,9 @@ +{ + "name": "Selma", + "profession": "Software Engineer", + "address": [ + "35 Fashion Street", + "London", + "E1 6PX" + ] +} diff --git a/jq/scores.json b/jq/scores.json new file mode 100644 index 0000000..d5f62bf --- /dev/null +++ b/jq/scores.json @@ -0,0 +1 @@ +[{"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-01.sh b/jq/script-01.sh new file mode 100755 index 0000000..95827f6 --- /dev/null +++ b/jq/script-01.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/jq/script-02.sh b/jq/script-02.sh new file mode 100755 index 0000000..21544d6 --- /dev/null +++ b/jq/script-02.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/jq/script-03.sh b/jq/script-03.sh new file mode 100755 index 0000000..3566f03 --- /dev/null +++ b/jq/script-03.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/jq/script-04.sh b/jq/script-04.sh new file mode 100755 index 0000000..015997e --- /dev/null +++ b/jq/script-04.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +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. +# Your output should contain 6 lines, each with just one word on it. +# Your output should not contain any quote characters. diff --git a/jq/script-05.sh b/jq/script-05.sh new file mode 100755 index 0000000..993fc9e --- /dev/null +++ b/jq/script-05.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/jq/script-06.sh b/jq/script-06.sh new file mode 100755 index 0000000..8b6e74c --- /dev/null +++ b/jq/script-06.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +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 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. diff --git a/jq/script-07.sh b/jq/script-07.sh new file mode 100755 index 0000000..d43f93d --- /dev/null +++ b/jq/script-07.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +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 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. diff --git a/jq/script-08.sh b/jq/script-08.sh new file mode 100755 index 0000000..6671fd1 --- /dev/null +++ b/jq/script-08.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +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 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. diff --git a/jq/script-09.sh b/jq/script-09.sh new file mode 100755 index 0000000..c2536a5 --- /dev/null +++ b/jq/script-09.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +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 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. diff --git a/jq/script-10.sh b/jq/script-10.sh new file mode 100755 index 0000000..8e9d75f --- /dev/null +++ b/jq/script-10.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/jq/script-11.sh b/jq/script-11.sh new file mode 100755 index 0000000..d2337a6 --- /dev/null +++ b/jq/script-11.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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. diff --git a/shell-pipelines/README.md b/shell-pipelines/README.md new file mode 100644 index 0000000..aec8e36 --- /dev/null +++ b/shell-pipelines/README.md @@ -0,0 +1,18 @@ +# Shell pipelines exercises + +This folder contains exercises to help you practice combining shell tools in pipelines. + +Each folder is named after a group of tools, and contains exercises to practice using them. + +You are not expected to use tools that weren't in the folder names to solve the problems, but you are allowed to if you want to! + +Each folder contains a number of scripts named `script-??.sh` as well as some files that are used by the scripts. You should look in the scripts one at a time and understand what you need to fix. + +When a script is complete, move on to the next script. + +When a folder is complete, move on to the next folder. + +Before running a script you should `cd` into the directory it's in. +You should write all of your scripts assuming they're running inside the directory they're saved in. + +You can approach the folders in any order. diff --git a/shell-pipelines/ls-grep/sample-files/Ariane b/shell-pipelines/ls-grep/sample-files/Ariane new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/Daniel b/shell-pipelines/ls-grep/sample-files/Daniel new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/HoChiMinh b/shell-pipelines/ls-grep/sample-files/HoChiMinh new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/KualaLumpur b/shell-pipelines/ls-grep/sample-files/KualaLumpur new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/Levi b/shell-pipelines/ls-grep/sample-files/Levi new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/London b/shell-pipelines/ls-grep/sample-files/London new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/NewYork b/shell-pipelines/ls-grep/sample-files/NewYork new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/Niamh b/shell-pipelines/ls-grep/sample-files/Niamh new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/Olga b/shell-pipelines/ls-grep/sample-files/Olga new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/York b/shell-pipelines/ls-grep/sample-files/York new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/cheese b/shell-pipelines/ls-grep/sample-files/cheese new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/dHondt b/shell-pipelines/ls-grep/sample-files/dHondt new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/goodbye b/shell-pipelines/ls-grep/sample-files/goodbye new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/hello b/shell-pipelines/ls-grep/sample-files/hello new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/sample-files/onions b/shell-pipelines/ls-grep/sample-files/onions new file mode 100644 index 0000000..e69de29 diff --git a/shell-pipelines/ls-grep/script-01.sh b/shell-pipelines/ls-grep/script-01.sh new file mode 100755 index 0000000..8c7d968 --- /dev/null +++ b/shell-pipelines/ls-grep/script-01.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/shell-pipelines/ls-grep/script-02.sh b/shell-pipelines/ls-grep/script-02.sh new file mode 100755 index 0000000..16f5f71 --- /dev/null +++ b/shell-pipelines/ls-grep/script-02.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/shell-pipelines/ls-grep/script-03.sh b/shell-pipelines/ls-grep/script-03.sh new file mode 100755 index 0000000..a302ab0 --- /dev/null +++ b/shell-pipelines/ls-grep/script-03.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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 new file mode 100755 index 0000000..c000b7e --- /dev/null +++ b/shell-pipelines/ls-grep/script-04.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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. diff --git a/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt b/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt new file mode 100644 index 0000000..f11a3c7 --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/events-with-timestamps.txt @@ -0,0 +1,10 @@ +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 +2024-11-26 10:04 Entry Mariana +2024-11-26 13:21 Exit Sally +2024-11-26 15:45 Entry Sally +2024-11-26 16:02 Entry German +2024-11-26 17:24 Exit Mariana +2024-11-26 18:18 Exit Sally diff --git a/shell-pipelines/sort-uniq-head-tail/events.txt b/shell-pipelines/sort-uniq-head-tail/events.txt new file mode 100644 index 0000000..c250d48 --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/events.txt @@ -0,0 +1,9 @@ +Entry Sally +Entry German +Exit German +Entry Mariana +Exit Sally +Entry Sally +Entry German +Exit Mariana +Exit Sally diff --git a/shell-pipelines/sort-uniq-head-tail/scores-table.txt b/shell-pipelines/sort-uniq-head-tail/scores-table.txt new file mode 100644 index 0000000..921ee6c --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/scores-table.txt @@ -0,0 +1,6 @@ +Ahmed London 1 10 4 +Basia London 22 9 6 +Mehmet Birmingham 3 12 17 +Leila London 1 +Piotr Glasgow 15 2 25 11 8 +Chandra Birmingham 12 6 diff --git a/shell-pipelines/sort-uniq-head-tail/script-01.sh b/shell-pipelines/sort-uniq-head-tail/script-01.sh new file mode 100755 index 0000000..171e1f9 --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-01.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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". diff --git a/shell-pipelines/sort-uniq-head-tail/script-02.sh b/shell-pipelines/sort-uniq-head-tail/script-02.sh new file mode 100755 index 0000000..29c3c25 --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-02.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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). diff --git a/shell-pipelines/sort-uniq-head-tail/script-03.sh b/shell-pipelines/sort-uniq-head-tail/script-03.sh new file mode 100755 index 0000000..bcbaf34 --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-03.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +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 lines for the three players with the highest first score, in descending order. +# Your output should be: +# Basia London 22 9 6 +# Piotr Glasgow 15 2 25 11 8 +# Chandra Birmingham 12 6 diff --git a/shell-pipelines/sort-uniq-head-tail/script-04.sh b/shell-pipelines/sort-uniq-head-tail/script-04.sh new file mode 100755 index 0000000..65a5cfb --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-04.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +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). diff --git a/shell-pipelines/sort-uniq-head-tail/script-05.sh b/shell-pipelines/sort-uniq-head-tail/script-05.sh new file mode 100755 index 0000000..a93cd9f --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-05.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +# The input for this script is the events.txt file. +# 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. diff --git a/shell-pipelines/sort-uniq-head-tail/script-06.sh b/shell-pipelines/sort-uniq-head-tail/script-06.sh new file mode 100755 index 0000000..715c7ae --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-06.sh @@ -0,0 +1,7 @@ +#!/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. diff --git a/shell-pipelines/sort-uniq-head-tail/script-07.sh b/shell-pipelines/sort-uniq-head-tail/script-07.sh new file mode 100755 index 0000000..7fd07e1 --- /dev/null +++ b/shell-pipelines/sort-uniq-head-tail/script-07.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +# The input for this script is the events-with-timestamps.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. +# The word "Event" should not appear in your script's output. diff --git a/shell-pipelines/tr/script-01.sh b/shell-pipelines/tr/script-01.sh new file mode 100755 index 0000000..8bb0211 --- /dev/null +++ b/shell-pipelines/tr/script-01.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +# The input for this script is the text.txt file, which contains an email. +# 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 (.). diff --git a/shell-pipelines/tr/script-02.sh b/shell-pipelines/tr/script-02.sh new file mode 100755 index 0000000..cf3a503 --- /dev/null +++ b/shell-pipelines/tr/script-02.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -euo pipefail + +# The input for this script is the text.txt file, which contains an email. +# Unfortunately, the author wrote it using a German keyboard which has the Y and Z keys swapped, +# 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). diff --git a/shell-pipelines/tr/text.txt b/shell-pipelines/tr/text.txt new file mode 100644 index 0000000..d1beda8 --- /dev/null +++ b/shell-pipelines/tr/text.txt @@ -0,0 +1,11 @@ +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! + +Hope zou're doing well, and enjoz the trip! + +Thanks, + +Karolina