West Midlands | SDC-July | Gabriel Deng | Sprint 2 | Jq-Exercises#109
West Midlands | SDC-July | Gabriel Deng | Sprint 2 | Jq-Exercises#109gai93003 wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
| # It looked delicious. | ||
| # I was tempted to take a bite of it. | ||
| # But this seemed like a bad idea... | ||
| cat -A ../helper-files/*.txt No newline at end of file |
There was a problem hiding this comment.
Just a note: -A shows some invisible characters like $ at the end of the line, it was not necessary here.
|
|
||
| # 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 'cure' < dialogue.txt No newline at end of file |
There was a problem hiding this comment.
You would need to use an option here to show the line before the line containing cure. Hint: check out https://man7.org/linux/man-pages/man1/grep.1.html (-B)
|
|
||
| # 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 '^Doctor' *.txt |
There was a problem hiding this comment.
Almost, you could also just print the file names. Check out --files-with-matches here: https://man7.org/linux/man-pages/man1/grep.1.html
| # 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 's/, \(^ \) /, /1' input.txt No newline at end of file |
There was a problem hiding this comment.
This doesn't add a space after the comma in the line 11, could you please double check?
| # 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 '.[] | "\(.name) \(.scores | length)"' scores.json No newline at end of file |
There was a problem hiding this comment.
Almost! There should be no quotes, I am getting this:
$ jq '.[] | "\(.name) \(.scores | length)"' scores.json
"Ahmed 3"
"Basia 3"
"Mehmet 3"
"Leila 1"
"Piotr 5"
"Chandra 2"
| # 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 '.[] | "\(.name) \(.scores | add)"' scores.json No newline at end of file |
|
|
||
| Convert the decimal number 14 to binary. | ||
| Answer: | ||
| Answer: 1110. |
There was a problem hiding this comment.
Could you please submit this as a separate PR if possible? One task per pr, I think jq was also a separate one :)
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.