diff --git a/.github/workflows/test-sdc-tasks.yml b/.github/workflows/test-sdc-tasks.yml new file mode 100644 index 00000000..30369dea --- /dev/null +++ b/.github/workflows/test-sdc-tasks.yml @@ -0,0 +1,59 @@ +name: Test SDC Tasks + +on: + pull_request_target: + types: + - labeled + - unlabeled + - opened + - edited + - reopened + +jobs: + test_sdc_tasks: + + name: Test SDC Tasks + runs-on: ubuntu-slim + permissions: + pull-requests: write + + steps: + - name: checkout pushed PR + uses: actions/checkout@v5 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v47.0.5 + - name: test individual shell tools + if: contains(steps.changed-files.outputs.all_changed_files, 'individual-shell-tools/awk/script-01.sh') + run: ./test-sdc.sh individual-shell-tools + shell: bash + - name: test jq + if: contains(steps.changed-files.outputs.all_changed_files, 'jq/script-01.sh') + run: ./test-sdc.sh jq + shell: bash + - name: test shell-pipelines + if: contains(steps.changed-files.outputs.all_changed_files, 'shell-pipelines/ls-grep/script-01.sh') + run: ./test-sdc.sh shell-pipelines + shell: bash + - name: make output comment + if: contains(steps.changed-files.outputs.all_changed_files, 'individual-shell-tools/awk/script-01.sh') || contains(steps.changed-files.outputs.all_changed_files, 'jq/script-01.sh') || contains(steps.changed-files.outputs.all_changed_files, 'shell-pipelines/ls-grep/script-01.sh') + env: + GH_TOKEN: ${{ secrets.MY_TOKEN }} + ISSUE_URL: ${{ github.event.issue.html_url }} + run: | + gh issue comment $ISSUE_URL --body-FILE testoutput.TXT + - name: read test output + if: contains(steps.changed-files.outputs.all_changed_files, 'individual-shell-tools/awk/script-01.sh') || contains(steps.changed-files.outputs.all_changed_files, 'jq/script-01.sh') || contains(steps.changed-files.outputs.all_changed_files, 'shell-pipelines/ls-grep/script-01.sh') + id: read-test-output + run: | + echo 'testoutput<> $GITHUB_OUTPUT + cat testoutput.txt >> $GITHUB_OUTPUT + echo EOF >> $GITHUB_OUTPUT + - name: add appropriate labels + if: contains(steps.read-test-output.outputs.testoutput, 'complete!') + env: + GH_TOKEN: ${{ secrets.MY_TOKEN }} + ISSUE_URL: ${{ github.event.issue.html_url }} + run: | + gh issue edit $ISSUE_URL --add-label "Complete" + gh issue edit $ISSUE_URL --remove-label "Needs Review" diff --git a/.gitignore b/.gitignore index 3c3629e6..c4234ab7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +testoutput.txt diff --git a/expect/individual-shell-tools/awk/script-01.sh b/expect/individual-shell-tools/awk/script-01.sh new file mode 100755 index 00000000..050f0437 --- /dev/null +++ b/expect/individual-shell-tools/awk/script-01.sh @@ -0,0 +1,6 @@ +Ahmed +Basia +Mehmet +Leila +Piotr +Chandra diff --git a/expect/individual-shell-tools/awk/script-02.sh b/expect/individual-shell-tools/awk/script-02.sh new file mode 100755 index 00000000..44e2e83e --- /dev/null +++ b/expect/individual-shell-tools/awk/script-02.sh @@ -0,0 +1,12 @@ +Ahmed London +Basia London +Mehmet Birmingham +Leila London +Piotr Glasgow +Chandra Birmingham +Ahmed London +Basia London +Mehmet Birmingham +Leila London +Piotr Glasgow +Chandra Birmingham diff --git a/expect/individual-shell-tools/awk/script-03.sh b/expect/individual-shell-tools/awk/script-03.sh new file mode 100755 index 00000000..f5d0b1f0 --- /dev/null +++ b/expect/individual-shell-tools/awk/script-03.sh @@ -0,0 +1,6 @@ +Ahmed 1 +Basia 22 +Mehmet 3 +Leila 1 +Piotr 15 +Chandra 12 diff --git a/expect/individual-shell-tools/awk/script-04.sh b/expect/individual-shell-tools/awk/script-04.sh new file mode 100755 index 00000000..6e95a2f5 --- /dev/null +++ b/expect/individual-shell-tools/awk/script-04.sh @@ -0,0 +1,3 @@ +Ahmed 4 +Basia 6 +Leila 1 diff --git a/expect/individual-shell-tools/awk/script-05.sh b/expect/individual-shell-tools/awk/script-05.sh new file mode 100755 index 00000000..dd7e1d36 --- /dev/null +++ b/expect/individual-shell-tools/awk/script-05.sh @@ -0,0 +1,6 @@ +Ahmed 3 +Basia 3 +Mehmet 3 +Leila 1 +Piotr 5 +Chandra 2 diff --git a/expect/individual-shell-tools/awk/script-06-stretch.sh b/expect/individual-shell-tools/awk/script-06-stretch.sh new file mode 100755 index 00000000..fb1e7bc8 --- /dev/null +++ b/expect/individual-shell-tools/awk/script-06-stretch.sh @@ -0,0 +1 @@ +54 diff --git a/expect/individual-shell-tools/awk/script-06.sh b/expect/individual-shell-tools/awk/script-06.sh new file mode 100644 index 00000000..e69de29b diff --git a/expect/individual-shell-tools/awk/script-07-stretch.sh b/expect/individual-shell-tools/awk/script-07-stretch.sh new file mode 100755 index 00000000..33ff777a --- /dev/null +++ b/expect/individual-shell-tools/awk/script-07-stretch.sh @@ -0,0 +1,6 @@ +Ahmed 15 +Basia 37 +Mehmet 32 +Leila 1 +Piotr 61 +Chandra 18 diff --git a/expect/individual-shell-tools/cat/script-01.sh b/expect/individual-shell-tools/cat/script-01.sh new file mode 100755 index 00000000..ed7bf7d0 --- /dev/null +++ b/expect/individual-shell-tools/cat/script-01.sh @@ -0,0 +1 @@ +Once upon a time... diff --git a/expect/individual-shell-tools/cat/script-02.sh b/expect/individual-shell-tools/cat/script-02.sh new file mode 100755 index 00000000..769b7e08 --- /dev/null +++ b/expect/individual-shell-tools/cat/script-02.sh @@ -0,0 +1,5 @@ +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/expect/individual-shell-tools/cat/script-03.sh b/expect/individual-shell-tools/cat/script-03.sh new file mode 100755 index 00000000..f97bd500 --- /dev/null +++ b/expect/individual-shell-tools/cat/script-03.sh @@ -0,0 +1,3 @@ + 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/expect/individual-shell-tools/cat/script-04-stretch.sh b/expect/individual-shell-tools/cat/script-04-stretch.sh new file mode 100755 index 00000000..6f35e89d --- /dev/null +++ b/expect/individual-shell-tools/cat/script-04-stretch.sh @@ -0,0 +1,5 @@ + 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/expect/individual-shell-tools/grep/script-01.sh b/expect/individual-shell-tools/grep/script-01.sh new file mode 100755 index 00000000..bc96ffe9 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-01.sh @@ -0,0 +1,6 @@ +Doctor: Hello +Doctor: What's wrong today? +Doctor: That sounds frustrating. When did this start? +Doctor: Say "Hi". +Doctor: You didn't say hello +Doctor: You're welcome, goodbye diff --git a/expect/individual-shell-tools/grep/script-02.sh b/expect/individual-shell-tools/grep/script-02.sh new file mode 100755 index 00000000..bad606e1 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-02.sh @@ -0,0 +1,9 @@ +Doctor: Hello +Patient: Hello Doctor +Doctor: What's wrong today? +Doctor: That sounds frustrating. When did this start? +Doctor: Say "Hi". +Doctor: You didn't say hello +Doctor: You're welcome, goodbye +Patient: I went to the doctor! +Spouse: I'm glad you saw the Doctor: did they cure you? diff --git a/expect/individual-shell-tools/grep/script-03.sh b/expect/individual-shell-tools/grep/script-03.sh new file mode 100755 index 00000000..ec635144 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-03.sh @@ -0,0 +1 @@ +9 diff --git a/expect/individual-shell-tools/grep/script-04.sh b/expect/individual-shell-tools/grep/script-04.sh new file mode 100755 index 00000000..5814afa2 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-04.sh @@ -0,0 +1,10 @@ +Doctor: What's wrong today? +Doctor: That sounds frustrating. When did this start? +Doctor: Say "Hi". +Patient: Hi +Patient: I seem to be cured! +Doctor: You're welcome, goodbye + +Patient: I went to the doctor! +Spouse: I'm glad you saw the Doctor: did they cure you? +Patient: Yes! diff --git a/expect/individual-shell-tools/grep/script-05.sh b/expect/individual-shell-tools/grep/script-05.sh new file mode 100755 index 00000000..2ed07ed2 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-05.sh @@ -0,0 +1,5 @@ +Doctor: You didn't say hello +Patient: I seem to be cured! +-- +Patient: I went to the doctor! +Spouse: I'm glad you saw the Doctor: did they cure you? diff --git a/expect/individual-shell-tools/grep/script-06.sh b/expect/individual-shell-tools/grep/script-06.sh new file mode 100755 index 00000000..87b3a4f5 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-06.sh @@ -0,0 +1,2 @@ +dialogue-2.txt +dialogue.txt diff --git a/expect/individual-shell-tools/grep/script-07.sh b/expect/individual-shell-tools/grep/script-07.sh new file mode 100755 index 00000000..aed78c63 --- /dev/null +++ b/expect/individual-shell-tools/grep/script-07.sh @@ -0,0 +1,3 @@ +dialogue-2.txt:2 +dialogue-3.txt:0 +dialogue.txt:6 diff --git a/expect/individual-shell-tools/ls/script-01.sh b/expect/individual-shell-tools/ls/script-01.sh new file mode 100755 index 00000000..dd590d62 --- /dev/null +++ b/expect/individual-shell-tools/ls/script-01.sh @@ -0,0 +1,5 @@ +child-directory +script-01.sh +script-02.sh +script-03.sh +script-04.sh diff --git a/expect/individual-shell-tools/ls/script-02.sh b/expect/individual-shell-tools/ls/script-02.sh new file mode 100755 index 00000000..bfd087e6 --- /dev/null +++ b/expect/individual-shell-tools/ls/script-02.sh @@ -0,0 +1,3 @@ +helper-1.txt +helper-2.txt +helper-3.txt diff --git a/expect/individual-shell-tools/ls/script-03.sh b/expect/individual-shell-tools/ls/script-03.sh new file mode 100755 index 00000000..36acd715 --- /dev/null +++ b/expect/individual-shell-tools/ls/script-03.sh @@ -0,0 +1,11 @@ +.: +child-directory +script-01.sh +script-02.sh +script-03.sh +script-04.sh + +./child-directory: +helper-1.txt +helper-2.txt +helper-3.txt diff --git a/expect/individual-shell-tools/ls/script-04.sh b/expect/individual-shell-tools/ls/script-04.sh new file mode 100755 index 00000000..86e7570e --- /dev/null +++ b/expect/individual-shell-tools/ls/script-04.sh @@ -0,0 +1,8 @@ +First exercise (sorted newest to oldest): +helper-3.txt +helper-1.txt +helper-2.txt +Second exercise (sorted oldest to newest): +helper-2.txt +helper-1.txt +helper-3.txt diff --git a/expect/individual-shell-tools/sed/script-01.sh b/expect/individual-shell-tools/sed/script-01.sh new file mode 100755 index 00000000..d92b03ab --- /dev/null +++ b/expect/individual-shell-tools/sed/script-01.sh @@ -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/expect/individual-shell-tools/sed/script-02.sh b/expect/individual-shell-tools/sed/script-02.sh new file mode 100755 index 00000000..e326bd4a --- /dev/null +++ b/expect/individual-shell-tools/sed/script-02.sh @@ -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: + Alisha + Jacob + Pietro + Katya + +We also should remember, when we go shopping, to get items: oranges,cheese,bread,olives. diff --git a/expect/individual-shell-tools/sed/script-03.sh b/expect/individual-shell-tools/sed/script-03.sh new file mode 100755 index 00000000..088b17d5 --- /dev/null +++ b/expect/individual-shell-tools/sed/script-03.sh @@ -0,0 +1,6 @@ +This is a sample file for experimenting with sed. + +It contains many lines, and there are some things you may want to do with each of them. + +We'll include some score information: + diff --git a/expect/individual-shell-tools/sed/script-04.sh b/expect/individual-shell-tools/sed/script-04.sh new file mode 100755 index 00000000..852fa155 --- /dev/null +++ b/expect/individual-shell-tools/sed/script-04.sh @@ -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/expect/individual-shell-tools/sed/script-05.sh b/expect/individual-shell-tools/sed/script-05.sh new file mode 100755 index 00000000..fe4d9d10 --- /dev/null +++ b/expect/individual-shell-tools/sed/script-05.sh @@ -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: +Alisha 37 +Jacob 15 +Pietro 7 +Katya 3 + +We also should remember, when we go shopping, to get 4 items: oranges,cheese,bread,olives. diff --git a/expect/individual-shell-tools/sed/script-06.sh b/expect/individual-shell-tools/sed/script-06.sh new file mode 100755 index 00000000..d9f950fe --- /dev/null +++ b/expect/individual-shell-tools/sed/script-06.sh @@ -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/expect/individual-shell-tools/wc/script-01.sh b/expect/individual-shell-tools/wc/script-01.sh new file mode 100755 index 00000000..d1ad53e8 --- /dev/null +++ b/expect/individual-shell-tools/wc/script-01.sh @@ -0,0 +1 @@ +19 ../helper-files/helper-3.txt diff --git a/expect/individual-shell-tools/wc/script-02.sh b/expect/individual-shell-tools/wc/script-02.sh new file mode 100755 index 00000000..6bd060b7 --- /dev/null +++ b/expect/individual-shell-tools/wc/script-02.sh @@ -0,0 +1 @@ +3 ../helper-files/helper-3.txt diff --git a/expect/individual-shell-tools/wc/script-03.sh b/expect/individual-shell-tools/wc/script-03.sh new file mode 100755 index 00000000..572716a4 --- /dev/null +++ b/expect/individual-shell-tools/wc/script-03.sh @@ -0,0 +1,4 @@ + 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/expect/jq/script-01.sh b/expect/jq/script-01.sh new file mode 100755 index 00000000..e16f4ed9 --- /dev/null +++ b/expect/jq/script-01.sh @@ -0,0 +1 @@ +Selma diff --git a/expect/jq/script-02.sh b/expect/jq/script-02.sh new file mode 100755 index 00000000..18711aff --- /dev/null +++ b/expect/jq/script-02.sh @@ -0,0 +1 @@ +35 Fashion Street, London, E1 6PX diff --git a/expect/jq/script-03.sh b/expect/jq/script-03.sh new file mode 100755 index 00000000..d63f6ec7 --- /dev/null +++ b/expect/jq/script-03.sh @@ -0,0 +1,2 @@ +Selma, Software Engineer +Selma, Software Engineer diff --git a/expect/jq/script-04.sh b/expect/jq/script-04.sh new file mode 100755 index 00000000..050f0437 --- /dev/null +++ b/expect/jq/script-04.sh @@ -0,0 +1,6 @@ +Ahmed +Basia +Mehmet +Leila +Piotr +Chandra diff --git a/expect/jq/script-05.sh b/expect/jq/script-05.sh new file mode 100755 index 00000000..ee7e0feb --- /dev/null +++ b/expect/jq/script-05.sh @@ -0,0 +1,6 @@ +Ahmed London +Basia London +Mehmet Birmingham +Leila London +Piotr Glasgow +Chandra Birmingham diff --git a/expect/jq/script-06.sh b/expect/jq/script-06.sh new file mode 100755 index 00000000..f5d0b1f0 --- /dev/null +++ b/expect/jq/script-06.sh @@ -0,0 +1,6 @@ +Ahmed 1 +Basia 22 +Mehmet 3 +Leila 1 +Piotr 15 +Chandra 12 diff --git a/expect/jq/script-07.sh b/expect/jq/script-07.sh new file mode 100755 index 00000000..59c783f1 --- /dev/null +++ b/expect/jq/script-07.sh @@ -0,0 +1,6 @@ +Ahmed 4 +Basia 6 +Mehmet 17 +Leila 1 +Piotr 8 +Chandra 6 diff --git a/expect/jq/script-08.sh b/expect/jq/script-08.sh new file mode 100755 index 00000000..dd7e1d36 --- /dev/null +++ b/expect/jq/script-08.sh @@ -0,0 +1,6 @@ +Ahmed 3 +Basia 3 +Mehmet 3 +Leila 1 +Piotr 5 +Chandra 2 diff --git a/expect/jq/script-09.sh b/expect/jq/script-09.sh new file mode 100755 index 00000000..33ff777a --- /dev/null +++ b/expect/jq/script-09.sh @@ -0,0 +1,6 @@ +Ahmed 15 +Basia 37 +Mehmet 32 +Leila 1 +Piotr 61 +Chandra 18 diff --git a/expect/jq/script-10.sh b/expect/jq/script-10.sh new file mode 100755 index 00000000..fb1e7bc8 --- /dev/null +++ b/expect/jq/script-10.sh @@ -0,0 +1 @@ +54 diff --git a/expect/jq/script-11.sh b/expect/jq/script-11.sh new file mode 100755 index 00000000..4e9bdff0 --- /dev/null +++ b/expect/jq/script-11.sh @@ -0,0 +1 @@ +164 diff --git a/expect/shell-pipelines/ls-grep/script-01.sh b/expect/shell-pipelines/ls-grep/script-01.sh new file mode 100755 index 00000000..5481774d --- /dev/null +++ b/expect/shell-pipelines/ls-grep/script-01.sh @@ -0,0 +1,11 @@ +Ariane +Daniel +HoChiMinh +KualaLumpur +Levi +London +NewYork +Niamh +Olga +York +dHondt diff --git a/expect/shell-pipelines/ls-grep/script-02.sh b/expect/shell-pipelines/ls-grep/script-02.sh new file mode 100755 index 00000000..35f2e44e --- /dev/null +++ b/expect/shell-pipelines/ls-grep/script-02.sh @@ -0,0 +1,10 @@ +Ariane +Daniel +HoChiMinh +KualaLumpur +Levi +London +NewYork +Niamh +Olga +York diff --git a/expect/shell-pipelines/ls-grep/script-03.sh b/expect/shell-pipelines/ls-grep/script-03.sh new file mode 100755 index 00000000..37ec4508 --- /dev/null +++ b/expect/shell-pipelines/ls-grep/script-03.sh @@ -0,0 +1,7 @@ +Ariane +Daniel +Levi +London +Niamh +Olga +York diff --git a/expect/shell-pipelines/ls-grep/script-04.sh b/expect/shell-pipelines/ls-grep/script-04.sh new file mode 100755 index 00000000..7f8f011e --- /dev/null +++ b/expect/shell-pipelines/ls-grep/script-04.sh @@ -0,0 +1 @@ +7 diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-01.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-01.sh new file mode 100755 index 00000000..a622bc92 --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-01.sh @@ -0,0 +1,6 @@ +Ahmed London 1 10 4 +Basia London 22 9 6 +Chandra Birmingham 12 6 +Leila London 1 +Mehmet Birmingham 3 12 17 +Piotr Glasgow 15 2 25 11 8 diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-02.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-02.sh new file mode 100755 index 00000000..c560f609 --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-02.sh @@ -0,0 +1,6 @@ +Basia London 22 9 6 +Piotr Glasgow 15 2 25 11 8 +Chandra Birmingham 12 6 +Mehmet Birmingham 3 12 17 +Leila London 1 +Ahmed London 1 10 4 diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-03.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-03.sh new file mode 100755 index 00000000..52d05bc6 --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-03.sh @@ -0,0 +1,3 @@ +Basia London 22 9 6 +Piotr Glasgow 15 2 25 11 8 +Chandra Birmingham 12 6 diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-04.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-04.sh new file mode 100755 index 00000000..9c18f93d --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-04.sh @@ -0,0 +1 @@ +Piotr Glasgow 15 2 25 11 8 diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-05.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-05.sh new file mode 100755 index 00000000..5b6440e3 --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-05.sh @@ -0,0 +1,6 @@ +Entry German +Entry Mariana +Entry Sally +Exit German +Exit Mariana +Exit Sally diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-06.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-06.sh new file mode 100755 index 00000000..93bd06bc --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-06.sh @@ -0,0 +1,2 @@ + 5 Entry + 4 Exit diff --git a/expect/shell-pipelines/sort-uniq-head-tail/script-07.sh b/expect/shell-pipelines/sort-uniq-head-tail/script-07.sh new file mode 100755 index 00000000..93bd06bc --- /dev/null +++ b/expect/shell-pipelines/sort-uniq-head-tail/script-07.sh @@ -0,0 +1,2 @@ + 5 Entry + 4 Exit diff --git a/expect/shell-pipelines/tr/script-01.sh b/expect/shell-pipelines/tr/script-01.sh new file mode 100755 index 00000000..8dea4ebf --- /dev/null +++ b/expect/shell-pipelines/tr/script-01.sh @@ -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 diff --git a/expect/shell-pipelines/tr/script-02.sh b/expect/shell-pipelines/tr/script-02.sh new file mode 100755 index 00000000..e00561af --- /dev/null +++ b/expect/shell-pipelines/tr/script-02.sh @@ -0,0 +1,11 @@ +Dear Zara, + +My apologies for sending this response so late. As you know, there's been a lot going on! + +Unfortunately I don't think I'll be able to make it to Zimbabwe, but but sounds amazing! + +Hope you're doing well, and enjoy the trip! + +Thanks, + +Karolina diff --git a/individual-shell-tools/awk/script-01.sh b/individual-shell-tools/awk/script-01.sh index 8db4390a..90e2397d 100755 --- a/individual-shell-tools/awk/script-01.sh +++ b/individual-shell-tools/awk/script-01.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player in `scores-table.txt`. # Your output should contain 6 lines, each with just one word on it. +awk '{print $1}' scores-table.txt diff --git a/individual-shell-tools/awk/script-02.sh b/individual-shell-tools/awk/script-02.sh index 5956be9b..a9e6a11c 100755 --- a/individual-shell-tools/awk/script-02.sh +++ b/individual-shell-tools/awk/script-02.sh @@ -4,3 +4,6 @@ set -euo pipefail # TODO: Write a command to output the names of each player, as well as their city. # Your output should contain 6 lines, each with two words on it, separated by a space. +awk '{print $1, $2}' scores-table.txt +# Or alternatively, if we need more control over the formatting: +awk '{printf "%s %s\n", $1, $2}' scores-table.txt diff --git a/individual-shell-tools/awk/script-03.sh b/individual-shell-tools/awk/script-03.sh index af7c6e8b..9c2945bf 100755 --- a/individual-shell-tools/awk/script-03.sh +++ b/individual-shell-tools/awk/script-03.sh @@ -5,3 +5,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the score from their first attempt. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 1". +awk '{printf "%s %s\n", $1, $3}' scores-table.txt diff --git a/individual-shell-tools/awk/script-04.sh b/individual-shell-tools/awk/script-04.sh index bf15703c..22f203a2 100755 --- a/individual-shell-tools/awk/script-04.sh +++ b/individual-shell-tools/awk/script-04.sh @@ -5,3 +5,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player in London along with the score from their last attempt. # Your output should contain 3 lines, each with one word and one number on it. # The first line should be "Ahmed 4". +awk '$2 == "London" {printf "%s %s\n", $1, $NF}' scores-table.txt diff --git a/individual-shell-tools/awk/script-05.sh b/individual-shell-tools/awk/script-05.sh index d1680cb0..53aafa22 100755 --- a/individual-shell-tools/awk/script-05.sh +++ b/individual-shell-tools/awk/script-05.sh @@ -5,3 +5,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the number of times they've played the game. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 3". +awk '{printf "%s %d\n", $1, NF-2}' scores-table.txt diff --git a/individual-shell-tools/awk/script-06-stretch.sh b/individual-shell-tools/awk/script-06-stretch.sh index 0201e637..841f6019 100755 --- a/individual-shell-tools/awk/script-06-stretch.sh +++ b/individual-shell-tools/awk/script-06-stretch.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output the total of adding together all players' first scores. # Your output should be exactly the number 54. +awk '{sum += $3} END {print sum}' scores-table.txt diff --git a/individual-shell-tools/awk/script-07-stretch.sh b/individual-shell-tools/awk/script-07-stretch.sh index 3f715588..fd95b80a 100755 --- a/individual-shell-tools/awk/script-07-stretch.sh +++ b/individual-shell-tools/awk/script-07-stretch.sh @@ -7,3 +7,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the total of adding all of that player's scores. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 15". The second line should be "Basia 37" +awk '{total=0 ; for (i=2; i<=NF; i++) {total += $i} ; print $1, total}' scores-table.txt diff --git a/individual-shell-tools/cat/script-01.sh b/individual-shell-tools/cat/script-01.sh index c85053e0..edcc54fb 100755 --- a/individual-shell-tools/cat/script-01.sh +++ b/individual-shell-tools/cat/script-01.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output the contents of the helper-1.txt file inside the helper-files directory to the terminal. # The output of this command should be "Once upon a time...". +cat ../helper-files/helper-1.txt diff --git a/individual-shell-tools/cat/script-02.sh b/individual-shell-tools/cat/script-02.sh index 01bbd5ea..d8187ff4 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/* diff --git a/individual-shell-tools/cat/script-03.sh b/individual-shell-tools/cat/script-03.sh index 37573b0c..dd6b1d8b 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 diff --git a/individual-shell-tools/cat/script-04-stretch.sh b/individual-shell-tools/cat/script-04-stretch.sh index 00fe3c48..70f8fdb6 100755 --- a/individual-shell-tools/cat/script-04-stretch.sh +++ b/individual-shell-tools/cat/script-04-stretch.sh @@ -13,3 +13,4 @@ set -euo pipefail # 3 It looked delicious. # 4 I was tempted to take a bite of it. # 5 But this seemed like a bad idea... +cat ../helper-files/* | cat -n diff --git a/individual-shell-tools/grep/script-01.sh b/individual-shell-tools/grep/script-01.sh index fb05f42f..f374150c 100755 --- a/individual-shell-tools/grep/script-01.sh +++ b/individual-shell-tools/grep/script-01.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output every line in dialogue.txt said by the Doctor. # The output should contain 6 lines. +grep "^Doctor:" dialogue.txt diff --git a/individual-shell-tools/grep/script-02.sh b/individual-shell-tools/grep/script-02.sh index df6f8564..31d35703 100755 --- a/individual-shell-tools/grep/script-02.sh +++ b/individual-shell-tools/grep/script-02.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output every line in dialogue.txt that contains the word Doctor (regardless of case). # The output should contain 9 lines. +grep -i "doctor" dialogue.txt diff --git a/individual-shell-tools/grep/script-03.sh b/individual-shell-tools/grep/script-03.sh index 5383fe57..f6f25b87 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 -i "doctor" dialogue.txt diff --git a/individual-shell-tools/grep/script-04.sh b/individual-shell-tools/grep/script-04.sh index 80ee0477..886a42ed 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 -v -i "hello" dialogue.txt diff --git a/individual-shell-tools/grep/script-05.sh b/individual-shell-tools/grep/script-05.sh index 1eb53818..8754273d 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 -B1 "cure" dialogue.txt diff --git a/individual-shell-tools/grep/script-06.sh b/individual-shell-tools/grep/script-06.sh index 5670e3b6..0e8244ff 100755 --- a/individual-shell-tools/grep/script-06.sh +++ b/individual-shell-tools/grep/script-06.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output the name of every `.txt` file in this directory which contains a line of dialogue said by the Doctor. # The output should contain two filenames. +grep -l "^Doctor:" *.txt diff --git a/individual-shell-tools/grep/script-07.sh b/individual-shell-tools/grep/script-07.sh index 9670ebad..9fabc87f 100755 --- a/individual-shell-tools/grep/script-07.sh +++ b/individual-shell-tools/grep/script-07.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output, for each `.txt` file in this directory, how many lines of dialogue the Doctor has. # The output should show that dialogue.txt contains 6 lines, dialogue-2.txt contains 2, and dialogue-3.txt contains 0. +grep -c "^Doctor:" *.txt diff --git a/individual-shell-tools/ls/script-01.sh b/individual-shell-tools/ls/script-01.sh index 241b62f5..c9cd189b 100755 --- a/individual-shell-tools/ls/script-01.sh +++ b/individual-shell-tools/ls/script-01.sh @@ -13,3 +13,4 @@ fi # TODO: Write a command to list the files and folders in this directory. # The output should be a list of names including child-directory, script-01.sh, script-02.sh, and more. +ls diff --git a/individual-shell-tools/ls/script-02.sh b/individual-shell-tools/ls/script-02.sh index d0a5a10f..d3717572 100755 --- a/individual-shell-tools/ls/script-02.sh +++ b/individual-shell-tools/ls/script-02.sh @@ -4,3 +4,4 @@ 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. +ls child-directory diff --git a/individual-shell-tools/ls/script-03.sh b/individual-shell-tools/ls/script-03.sh index 781216d2..5161171e 100755 --- a/individual-shell-tools/ls/script-03.sh +++ b/individual-shell-tools/ls/script-03.sh @@ -5,3 +5,4 @@ set -euo pipefail # TODO: Write a command which _recursively_ lists all of the files and folders in this directory _and_ all of the files inside those folders. # The output should be a list of names including: child-directory, script-01.sh, helper-1.txt (and more). # The formatting of the output doesn't matter. +ls -R diff --git a/individual-shell-tools/ls/script-04.sh b/individual-shell-tools/ls/script-04.sh index 72f3817b..b4bdb1f5 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 -1 -t child-directory echo "Second exercise (sorted oldest to newest):" # TODO: Write a command which does the same as above, but sorted in the opposite order (oldest first). # The output should be a list of names in this order, one per line: helper-2.txt, helper-1.txt, helper-3.txt. +ls -1 -t -r child-directory diff --git a/individual-shell-tools/sed/script-02.sh b/individual-shell-tools/sed/script-02.sh index abdd64d0..be485a0a 100755 --- a/individual-shell-tools/sed/script-02.sh +++ b/individual-shell-tools/sed/script-02.sh @@ -5,3 +5,4 @@ set -euo pipefail # TODO: Write a command to output input.txt with numbers removed. # The output should contain 11 lines. # Line 6 of the output should be " Alisha". +sed 's/[0-9]//g' input.txt diff --git a/individual-shell-tools/sed/script-03.sh b/individual-shell-tools/sed/script-03.sh index dd284a29..cebc0912 100755 --- a/individual-shell-tools/sed/script-03.sh +++ b/individual-shell-tools/sed/script-03.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output input.txt removing any line which contains a number. # The output should contain 6 lines. +sed -e '/[0-9]/d' input.txt diff --git a/individual-shell-tools/sed/script-04.sh b/individual-shell-tools/sed/script-04.sh index 0052ac6c..3b6ed6f1 100755 --- a/individual-shell-tools/sed/script-04.sh +++ b/individual-shell-tools/sed/script-04.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output input.txt replacing every occurrence of the string "We'll" with "We will". # The output should contain 11 lines. +sed -e "s/We\'ll/We will/g" input.txt diff --git a/individual-shell-tools/sed/script-05.sh b/individual-shell-tools/sed/script-05.sh index 2dcc91a0..d5305aa9 100755 --- a/individual-shell-tools/sed/script-05.sh +++ b/individual-shell-tools/sed/script-05.sh @@ -6,3 +6,4 @@ set -euo pipefail # If a line starts with a number and a space, make the line instead end with a space and the number. # So line 6 which currently reads "37 Alisha" should instead read "Alisha 37". # The output should contain 11 lines. +sed -e 's/^\([0-9]*\) \(.*\)$/\2 \1/' input.txt diff --git a/individual-shell-tools/sed/script-06.sh b/individual-shell-tools/sed/script-06.sh index 0b939017..9d685b3b 100755 --- a/individual-shell-tools/sed/script-06.sh +++ b/individual-shell-tools/sed/script-06.sh @@ -8,3 +8,4 @@ set -euo pipefail # The output should contain 11 lines. # Line 3 should be "It contains many lines, and there are some things you may want to do with each of them.". # Line 11 should be "We also should remember, when we go shopping, to get 4 items: oranges, cheese, bread, olives.". +sed -e 's/,\([^ ]\)/, \1/g' input.txt diff --git a/individual-shell-tools/wc/script-01.sh b/individual-shell-tools/wc/script-01.sh index c9dd6e5d..c944eeaf 100755 --- a/individual-shell-tools/wc/script-01.sh +++ b/individual-shell-tools/wc/script-01.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output the number of words in the file helper-files/helper-3.txt. # The output should include the number 19. The output should not include the number 92. +wc -w ../helper-files/helper-3.txt diff --git a/individual-shell-tools/wc/script-02.sh b/individual-shell-tools/wc/script-02.sh index 8feeb1a6..16e53091 100755 --- a/individual-shell-tools/wc/script-02.sh +++ b/individual-shell-tools/wc/script-02.sh @@ -4,3 +4,4 @@ set -euo pipefail # TODO: Write a command to output the number of lines in the file helper-files/helper-3.txt. # The output should include the number 3. The output should not include the number 19. +wc -l ../helper-files/helper-3.txt diff --git a/individual-shell-tools/wc/script-03.sh b/individual-shell-tools/wc/script-03.sh index 6b2e9d3d..6ac2210d 100755 --- a/individual-shell-tools/wc/script-03.sh +++ b/individual-shell-tools/wc/script-03.sh @@ -8,3 +8,4 @@ set -euo pipefail # 1 7 39 ../helper-files/helper-2.txt # 3 19 92 ../helper-files/helper-3.txt # 5 30 151 total +wc ../helper-files/* diff --git a/jq/script-01.sh b/jq/script-01.sh index 95827f68..0d69705d 100755 --- a/jq/script-01.sh +++ b/jq/script-01.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the name of the person. # Your output should be exactly the string "Selma", but should not contain any quote characters. +jq -r '.name' person.json diff --git a/jq/script-02.sh b/jq/script-02.sh index 21544d67..74a3ded8 100755 --- a/jq/script-02.sh +++ b/jq/script-02.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the address of the person, all on one line, with a comma between each line. # Your output should be exactly the string "35 Fashion Street, London, E1 6PX", but should not contain any quote characters. +jq -r '.address | join(", ")' person.json diff --git a/jq/script-03.sh b/jq/script-03.sh index 3566f03b..6a2f566a 100755 --- a/jq/script-03.sh +++ b/jq/script-03.sh @@ -5,3 +5,6 @@ set -euo pipefail # The input for this script is the person.json file. # TODO: Write a command to output the name of the person, then a comma, then their profession. # Your output should be exactly the string "Selma, Software Engineer", but should not contain any quote characters. +jq -r '[ .name, .profession ] | join(", ")' person.json +# Or alternatively, we can do two selects in a string interpolation: +jq -r '"\(.name), \(.profession)"' person.json diff --git a/jq/script-04.sh b/jq/script-04.sh index 015997e1..e50f742a 100755 --- a/jq/script-04.sh +++ b/jq/script-04.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player, one per line. # Your output should contain 6 lines, each with just one word on it. # Your output should not contain any quote characters. +jq -r '.[].name' scores.json diff --git a/jq/script-05.sh b/jq/script-05.sh index 993fc9ee..ab78fbad 100755 --- a/jq/script-05.sh +++ b/jq/script-05.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores.json file. # TODO: Write a command to output the names of each player, as well as their city. # Your output should contain 6 lines, each with two words on it. +jq -r '.[] | "\(.name) \(.city)"' scores.json diff --git a/jq/script-06.sh b/jq/script-06.sh index 8b6e74c5..47fee35b 100755 --- a/jq/script-06.sh +++ b/jq/script-06.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the score from their first attempt. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 1" with no quotes. +jq -r '.[] | "\(.name) \(.scores[0])"' scores.json diff --git a/jq/script-07.sh b/jq/script-07.sh index d43f93d1..f20ab3d7 100755 --- a/jq/script-07.sh +++ b/jq/script-07.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the score from their last attempt. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 4" with no quotes. +jq -r '.[] | "\(.name) \(.scores[-1])"' scores.json diff --git a/jq/script-08.sh b/jq/script-08.sh index 6671fd1b..165e67a4 100755 --- a/jq/script-08.sh +++ b/jq/script-08.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the number of times they've played the game. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 3" with no quotes. +jq -r '.[] | "\(.name) \(.scores | length)"' scores.json diff --git a/jq/script-09.sh b/jq/script-09.sh index c2536a53..3ce4c2b7 100755 --- a/jq/script-09.sh +++ b/jq/script-09.sh @@ -6,3 +6,4 @@ set -euo pipefail # TODO: Write a command to output just the names of each player along with the total scores from all of their games added together. # Your output should contain 6 lines, each with one word and one number on it. # The first line should be "Ahmed 15" with no quotes. +jq -r '.[] | "\(.name) \(.scores | add)"' scores.json diff --git a/jq/script-10.sh b/jq/script-10.sh index 8e9d75f0..8b124325 100755 --- a/jq/script-10.sh +++ b/jq/script-10.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores.json file. # TODO: Write a command to output the total of adding together all players' first scores. # Your output should be exactly the number 54. +jq -r '[.[].scores[0]] | add' scores.json diff --git a/jq/script-11.sh b/jq/script-11.sh index d2337a6b..da686da5 100755 --- a/jq/script-11.sh +++ b/jq/script-11.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores.json file. # TODO: Write a command to output the total of adding together all scores from all games from all players. # Your output should be exactly the number 164. +jq -r '[.[].scores | add] | add' scores.json diff --git a/number-systems/README.md b/number-systems/README.md index 77a3bde9..da424df4 100644 --- a/number-systems/README.md +++ b/number-systems/README.md @@ -5,61 +5,61 @@ Do not convert any binary numbers to decimal when solving a question unless the The goal of these exercises is for you to gain an intuition for binary numbers. Using tools to solve the problems defeats the point. Convert the decimal number 14 to binary. -Answer: +Answer: 1110 Convert the binary number 101101 to decimal: -Answer: +Answer: 45 Which is larger: 1000 or 0111? -Answer: +Answer: 1000 Which is larger: 00100 or 01011? -Answer: +Answer: 01011 What is 10101 + 01010? -Answer: +Answer: 11111 What is 10001 + 10001? -Answer: +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: +Answer: 15 How many bits would you need in order to store the numbers between 0 and 255 inclusive? -Answer: +Answer: 8 How many bits would you need in order to store the numbers between 0 and 3 inclusive? -Answer: +Answer: 2 How many bits would you need in order to store the numbers between 0 and 1000 inclusive? -Answer: +Answer: 10, but you'd have 23 spare values, so you can actually store between 0 and 1023 with 10 bits. How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)? -Answer: +Answer: Test that it has exactly one 1. Convert the decimal number 14 to hex. -Answer: +Answer: E Convert the decimal number 386 to hex. -Answer: +Answer: 182 Convert the hex number 386 to decimal. -Answer: +Answer: 902 Convert the hex number B to decimal. -Answer: +Answer: 11 If reading the byte 0x21 as a number, what decimal number would it mean? -Answer: +Answer: 33 If reading the byte 0x21 as an ASCII character, what character would it mean? -Answer: +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: +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: +Answer: Purple. If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be? -Answer: +Answer: 170, 0, 255 diff --git a/shell-pipelines/ls-grep/script-01.sh b/shell-pipelines/ls-grep/script-01.sh index 8c7d968a..b77993b2 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 16f5f71d..4fa4206c 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]' diff --git a/shell-pipelines/ls-grep/script-03.sh b/shell-pipelines/ls-grep/script-03.sh index a302ab03..9b79f1c8 100755 --- a/shell-pipelines/ls-grep/script-03.sh +++ b/shell-pipelines/ls-grep/script-03.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 and doesn't contain any other upper case letters. # Your output should contain 7 files. +ls sample-files | grep '^[A-Z][^A-Z]*$' diff --git a/shell-pipelines/ls-grep/script-04.sh b/shell-pipelines/ls-grep/script-04.sh index c000b7e3..b9b1fef9 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 '^[A-Z][^A-Z]*$' | wc -l diff --git a/shell-pipelines/sort-uniq-head-tail/script-01.sh b/shell-pipelines/sort-uniq-head-tail/script-01.sh index 171e1f98..845ad89d 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-01.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-01.sh @@ -5,3 +5,4 @@ set -euo pipefail # The input for this script is the scores-table.txt file. # TODO: Write a command to output scores-table.txt, with lines sorted by the person's name. # The first line of your output should be "Ahmed London 1 10 4" (with no quotes). And the third line should be "Chandra Birmingham 12 6". +sort scores-table.txt diff --git a/shell-pipelines/sort-uniq-head-tail/script-02.sh b/shell-pipelines/sort-uniq-head-tail/script-02.sh index 29c3c252..baa6b861 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 -r scores-table.txt diff --git a/shell-pipelines/sort-uniq-head-tail/script-03.sh b/shell-pipelines/sort-uniq-head-tail/script-03.sh index bcbaf342..23eb6792 100755 --- a/shell-pipelines/sort-uniq-head-tail/script-03.sh +++ b/shell-pipelines/sort-uniq-head-tail/script-03.sh @@ -8,3 +8,4 @@ set -euo pipefail # Basia London 22 9 6 # Piotr Glasgow 15 2 25 11 8 # Chandra Birmingham 12 6 +sort -n -k3 -r scores-table.txt | head -n3 diff --git a/shell-pipelines/sort-uniq-head-tail/script-04.sh b/shell-pipelines/sort-uniq-head-tail/script-04.sh index 65a5cfba..93c88aa9 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 -n -k3 -r scores-table.txt | tail -n+2 | head -n1 diff --git a/shell-pipelines/sort-uniq-head-tail/script-05.sh b/shell-pipelines/sort-uniq-head-tail/script-05.sh index a93cd9f9..8eba57e3 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 diff --git a/shell-pipelines/sort-uniq-head-tail/script-06.sh b/shell-pipelines/sort-uniq-head-tail/script-06.sh index 715c7ae5..e2fc1be4 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. +awk '{print $1}' events.txt | sort | uniq -c diff --git a/shell-pipelines/sort-uniq-head-tail/script-07.sh b/shell-pipelines/sort-uniq-head-tail/script-07.sh index 7fd07e1f..ed7481d6 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 diff --git a/shell-pipelines/tr/script-01.sh b/shell-pipelines/tr/script-01.sh index 8bb0211e..75c3ed25 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 '!' '.' diff --git a/shell-pipelines/tr/script-02.sh b/shell-pipelines/tr/script-02.sh index cf3a503a..f8c4121c 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 'yzYZ' 'zyZY' diff --git a/test-sdc.sh b/test-sdc.sh new file mode 100755 index 00000000..2d5341e8 --- /dev/null +++ b/test-sdc.sh @@ -0,0 +1,90 @@ +# This test file will be automatically run when you submit a pull request +# You should not modify this file +# You can run this file using ./test-sdc.sh task-directory-name to check your output +# You can use it with the individual-shell-tools, jq, and shell-pipelines tasks + +rm testoutput.txt +if [[ "$1" == "individual-shell-tools" ]]; then + cd individual-shell-tools + pass=0 + total=0 + for directory in */; do + cd $directory + if [ "$directory" == "helper-files/" ]; then + cd .. + continue + fi + for exercise in *.sh; do + total=$(($total+1)) + ./$exercise > ../../test.tmp + cmp ../../test.tmp ../../expect/individual-shell-tools/$directory$exercise --quiet + if [ $? -eq 0 ]; then + pass=$(($pass+1)) + else + if [[ "$exercise" == *"stretch"* ]]; then + # echo "Stretch task $directory$exercise failing, you can ignore this if you did not attempt. If you didnt, please have the volunteer check this." + echo "" >> ../../testoutput.txt + total=$(($total-1)) + else + echo "Failed $directory$exercise, please either attempt again or have the volunteer check this." >> ../../testoutput.txt + fi + fi + done + cd .. + done + cd .. + rm test.tmp + echo "You passed $pass/$total tasks." >> testoutput.txt + if [ $pass -ge $total ]; then + echo "This task is complete!" >> testoutput.txt + fi + cat testoutput.txt +elif [[ "$1" == "shell-pipelines" ]]; then + cd shell-pipelines + pass=0 + total=0 + for directory in */; do + cd $directory + for exercise in *.sh; do + total=$(($total+1)) + ./$exercise > ../../test.tmp + cmp ../../test.tmp ../../expect/shell-pipelines/$directory$exercise --quiet + if [ $? -eq 0 ]; then + pass=$(($pass+1)) + else + echo "Failed $directory$exercise, please either attempt again or have the volunteer check this." >> ../../testoutput.txt + fi + done + cd .. + done + cd .. + rm test.tmp + echo "You passed $pass/$total tasks." >> testoutput.txt + if [ $pass -eq $total ]; then + echo "This task is complete!" >> testoutput.txt + fi + cat testoutput.txt +elif [[ "$1" == "jq" ]]; then + cd jq + pass=0 + total=0 + for exercise in *.sh; do + total=$(($total+1)) + ./$exercise > ../test.tmp + cmp ../test.tmp ../expect/jq/$exercise --quiet + if [ $? -eq 0 ]; then + pass=$(($pass+1)) + else + echo "Failed $directory$exercise, please either attempt again or have the volunteer check this." >> ../../testoutput.txt + fi + done + cd .. + rm test.tmp + echo "You passed $pass/$total tasks." >> testoutput.txt + if [ $pass -eq $total ]; then + echo "This task is complete!" >> testoutput.txt + fi + cat testoutput.txt +else + echo "Please run this with a valid test directory name as argument" +fi