-
-
Notifications
You must be signed in to change notification settings - Fork 42
London | Nadika Zavodovska | Module-Tools | Sprint 1 | Individual-Shell-Tools #31
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?
London | Nadika Zavodovska | Module-Tools | Sprint 1 | Individual-Shell-Tools #31
Conversation
ehwus
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.
Great work Nadika! All of your scripts matched the expected output perfectly, and were all clear and readable. I particularly enjoyed seeing your comments explaining what your commands were actually doing, they were all very sensible additions to make your scripts clearer and more maintainable.
|
|
||
| awk '{print $1}' scores-table.txt | ||
|
|
||
| # '{print $1}' - output only the names from the first field. No newline at end of file |
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.
praise: Great to see your working in the comments here
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.
Thank you!
| # 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 |
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.
praise: This is a really clear and elegant solution to the problem!
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.
@ehwus Alex, thank you! I really appreciate your feedback!
| # 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 '{scoreSum = 0; for( i = 3; i <= NF; i++) scoreSum += $i; print $1, scoreSum}' scores-table.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.
question: What would be different if we didn't initialise the scoreSum variable here? Why might that cause unexpected behaviour?
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.
@ehwus Alex, thank you for a great question. If we don’t set scoreSum = 0, it may keep numbers from the line before, which could make the totals incorrect. Setting it to 0 means each player’s score starts from zero, so the result is right.
| # I was tempted to take a bite of it. | ||
| # But this seemed like a bad idea... | ||
|
|
||
| cat ../helper-files/* |
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.
praise: Great use of the wildcard here, I'm sure it will come in useful!
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.
Thank you!
|
|
||
| grep -i -v "Hello" dialogue.txt | ||
|
|
||
| # -v - inverts, return lines that don't contain "Hello" or "hello" No newline at end of file |
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.
question: are you sure about which does which here?
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.
@ehwus Alex, I think so. The -i option ignores the case (so it matches "Hello", "hello"), and -v inverts the match, showing lines that don’t contain "Hello".
| sed 's/^\([0-9]\+\) \(.*\)$/\2 \1/' input.txt | ||
|
|
||
| # \([0-9]\+\ - matches one or more digits. | ||
| # \(.*\)$/\2 \1/ - matches the rest of the line (2 - part after digit, 1 - part with digit). No newline at end of file |
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.
praise: These explanations in comments become more useful the more complex our code becomes, and the world would be a better place if everyone always left these sorts of comments when they write regular expressions!
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.
@ehwus Alex, thank you so much for your kind comment! I completely agree, well-commented code helps everyone, especially when dealing with complex regular expressions. Your feedback motivates me to keep up the practice!
|
Thank you for the great feedback, @ehwus Alex! I’m glad to hear the scripts worked well. Your encouragement motivates me to keep writing clear, understandable code and adding comments for better maintainability! |
Hi,
I've done all the tasks for the individual-shell-tools.
Self checklist
Thank you.