-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
London| Elhadj Abdoul Diallo| Module-Tools | WEEK1 - Individual-shell-tools #16
base: main
Are you sure you want to change the base?
Changes from all commits
911cd92
8b16334
f062d6d
18080a1
2798631
8467560
68070ec
1928e79
336b8aa
1211ee7
50606f2
5bb3577
c445a6b
86617b7
65f3f5b
ae357f2
eb4109f
988f5f9
d47bfbb
dc54635
ec4ce2a
7d99d30
b79d94d
a7e7ada
08b42da
e195344
f8f08c5
1e8bf64
234070e
f65408d
df28eb6
1a43a45
779cb97
7588543
5715882
16e8e79
940f691
3bb6a94
e2abd25
3dba76e
c544e75
7fe9ad0
8828953
697e210
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
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". | ||
# Output the names of each player in London along with the score from their last attempt. | ||
# For lines with fewer than 5 columns, print the last column. | ||
awk '{if (NF >= 5 && $2 == "London") print $1, $5; else if (NF < 5 && $2 == "London") print $1, $NF}' scores-table.txt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow, very nice work! (especially, because if you look at the current the latest changes for this in the repo, the condition for "For lines with fewer than 5 columns, print the last column." was taken out) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 '{ for(i = 3; i <= NF; i++) sum += $i; print $1, sum; sum = 0 }' scores-table.txt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i noticed you set initial value for sum at the end of the block - would it be better to initialise sum in another way? (regardless, your solution does print out the correct solution!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I could have done it at the biginning like this: awk '{ sum= 0; for(i = 3; i <= NF; i++) sum += $i; print $1, sum}' scores-table.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you would you use double quotes, how would this solution look like? what would be the advantage (if any) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the result would be the same. The advantage of using the double quote is that it handle speacial characters. This command is working because there is one does not include any special character. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ set -euo pipefail | |
# 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 input.txt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what would the option -e mean for this script? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it specifies multiple editing commands in a single |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (optional) how would you change this script if you need to use basic regular expressions? (congrats on using ERE ! ) |
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.
how would your script look like if you used printf instead of print? what would be the advantage (if any) to use printf?
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.
That's a good question! I've never tried printf before with
awk
but I guess it would allow me to format the result but as the content of the file is alreay in text format print is enough in this case