-
-
Notifications
You must be signed in to change notification settings - Fork 42
ZA | 25-SDC-July | Luke Manyamazi | Sprint 1 | Individual Shell Tools #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ZA | 25-SDC-July | Luke Manyamazi | Sprint 1 | Individual Shell Tools #121
Conversation
LonMcGregor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work on these tasks - I've left comments on a few of your solutions you could have another go with
| # 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:" "$(dirname "$0")"/*.txt | while IFS= read -r filepath; do | ||
| basename "$filepath" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -l argument will make it print the filename - why are you using the basename command as well?
|
|
||
| # 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:' "$(dirname "$0")"/*.txt | while IFS=: read -r file count; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you complete this solution using only a single grep command?
| # 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. | ||
| cd /home/luke/CYF/SDC/Module-Tools/individual-shell-tools/ls/child-directory | ||
| ls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you complete this task without first cd-ing into the directory?
| # TODO: Write a command to output input.txt with all occurrences of the letter `i` replaced with `I`. | ||
| # The output should contain 11 lines. | ||
| # The first line of the output should be: "ThIs Is a sample fIle for experImentIng with sed.". | ||
| sed 's/i/I/g' "$(dirname "$0")/input.txt" | while IFS= read -r line; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the part of your command after the pipe for this to work?
|
|
||
| # 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 's/We'\''ll/We will/g' "$(dirname "$0")"/input.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how you could rewrite this command to not need so many quote escape sequences?
|
|
||
| # 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 "$(dirname "$0")"/../helper-files/helper-3.txt | awk '{print $1}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to pipe to awk here?
| # 1 7 39 ../helper-files/helper-2.txt | ||
| # 3 19 92 ../helper-files/helper-3.txt | ||
| # 5 30 151 total | ||
| wc -lwm "$(dirname "$0")"/../helper-files/*.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to give the -lwm arguments here?
|
Do you want me to work on these before marking the PR as complete or you are suggesting for me to try them out? |
|
@Luke-Manyamazi Yes, could you consider the questions I ask and see if there are changes you could make to the code to address any issues please. |
|
Thank you @LonMcGregor I have updated my scripts and they are ready for further review. |
|
Great work! |
Learners, PR Template
Self checklist
Changelist
Completed the Individual Shell Tools exercises.
Each shell tool in its own folder (awk, cat, grep, ls, sed, wc) with scripts demonstrating how to use each command and combine them effectively. Using $(dirname "$0") for script-relative paths.
#!/bin/bash
set -euo pipefail
The above were already included in the template, but I took time to research and understand what each of them does before continuing.
Questions
Are the solutions clear and readable enough?
Any suggestions for improving how I handle errors or edge cases?