Manchester | 26-SDC-Jul | Fithi-Teklom | Sprint 1 | Individual-shell-tools#567
Manchester | 26-SDC-Jul | Fithi-Teklom | Sprint 1 | Individual-shell-tools#567Fithi-Teklom wants to merge 9 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
SlideGauge
left a comment
There was a problem hiding this comment.
A lot of files do not have trailing new line, add it please as well
| # 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 No newline at end of file |
There was a problem hiding this comment.
helper-files/ is a sibling of these folders, not a child.
| # 2 I was tempted to take a bite of it. | ||
| # 3 But this seemed like a bad idea... | ||
|
|
||
| cat -n helper-files/helper-3.txt No newline at end of file |
There was a problem hiding this comment.
helper-files/ is a sibling of these folders, not a child.
| # I was tempted to take a bite of it. | ||
| # But this seemed like a bad idea... | ||
|
|
||
| cat helper-files/* No newline at end of file |
There was a problem hiding this comment.
helper-files/ is a sibling of these folders, not a child.
| # 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 No newline at end of file |
There was a problem hiding this comment.
helper-files/ is a sibling of these folders, not a child.
| # 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 No newline at end of file |
There was a problem hiding this comment.
helper-files/ is a sibling of these folders, not a child.
| # 3 19 92 ../helper-files/helper-3.txt | ||
| # 5 30 151 total | ||
|
|
||
| wc helper-files/* No newline at end of file |
There was a problem hiding this comment.
helper-files/ is a sibling of these folders, not a child.
| # 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 |
There was a problem hiding this comment.
Does it grabs only lines said by a doctor, not something like "Hello, Doctor!"?
| # 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 No newline at end of file |
There was a problem hiding this comment.
The line is commented, what was intended here to happen?
| # 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 "We'll/We will/g" No newline at end of file |
There was a problem hiding this comment.
How does it know which file to look into?
| # 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 -1t child-directory |
|
Could you address my comments please? |
I have corrected the mistakes. |
|
Results of test: |
SlideGauge
left a comment
There was a problem hiding this comment.
Thanks for the update — the command logic is mostly correct now, and the awk/sed solutions show good understanding. However the tests still fail 24/28, and the root cause is the same for almost every script: file paths.
The README for this exercise says:
Before running a script you should
cdinto the directory it's in. You should write all of your scripts assuming they're running inside the directory they're saved in.
Paths like individual-shell-tools/awk/scores-table.txt only work when the script is run from the repository root — the tests run each script from its own folder. So:
- in
awkscripts:scores-table.txt - in
grepscripts:dialogue.txt/*.txt - in
sedscripts:input.txt - in
cat/wcscripts:../helper-files/...(this is what my earlier "sibling" comments meant — from insidecat/, go up one level with.., then intohelper-files/)
Your ls scripts already do this correctly — that's exactly why they are the 4 that pass.
Also, most files are still missing the trailing newline I asked about in my previous review — please add it to all scripts.
Tip for checking your work before pushing: cd into each folder and run the script, e.g. cd individual-shell-tools/awk then ./script-01.sh — if it errors or prints the wrong thing there, the test will fail too.
|
|
||
| # 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}' individual-shell-tools/awk/scores-table.txt No newline at end of file |
There was a problem hiding this comment.
🔴 This path only works when the script is run from the repository root. Per the README, scripts are run from their own directory — so this should just be scores-table.txt. The same applies to all of your awk, grep and sed scripts.
| # 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 individual-shell-tools/helper-files/helper-1.txt No newline at end of file |
There was a problem hiding this comment.
🔴 Closer than before, but this still assumes the script is run from the repository root. From inside the cat/ folder, you reach helper-files/ with ../helper-files/helper-1.txt — that's what "sibling" means: go up one level with .., then into the folder. Same fix for the other cat and wc scripts.
| # TODO: Write a command to output every line in dialogue.txt said by the Doctor. | ||
| # The output should contain 6 lines. | ||
|
|
||
| grep "Doctor" individual-shell-tools/grep/dialogue.txt No newline at end of file |
There was a problem hiding this comment.
🔴 This is the same issue I raised in my previous review: grep "Doctor" matches any line containing the word, so you get 8 lines — including Patient: Hello Doctor and the Spouse's line — while the task expects the 6 lines said by the Doctor. You already solved this in script-07 with ^Doctor: — use the same idea here.
| # 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" individual-shell-tools/grep/*.txt No newline at end of file |
There was a problem hiding this comment.
🟡 This happens to output the right two files, but a bit by luck — "Doctor" matches any mention of the word, not only lines the Doctor says. ^Doctor: (like your script-07) expresses exactly what the task asks and won't break if a file merely mentions the Doctor.
| # 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=3;i<=NF;i++) total += $i; print $1, total}' individual-shell-tools/awk/scores-table.txt No newline at end of file |
There was a problem hiding this comment.
🟢 Nice work on the stretch goal — looping over the fields with for(i=3;i<=NF;i++) is exactly the right approach here.
| # So line 6 which currently reads "37 Alisha" should instead read "Alisha 37". | ||
| # The output should contain 11 lines. | ||
|
|
||
| sed 's/^\([0-9][0-9]*\) \(.*\)$/\2 \1/' individual-shell-tools/sed/input.txt No newline at end of file |
There was a problem hiding this comment.
🟢 Good use of capture groups to swap the number and the name — this is a tricky exercise and your regex is correct.
Self checklist
Changelist
Completed the shell tools exercises covering ls, cat, wc, grep, sed, and awk.
What was added: