London | 26-SDC-Mar | Craig D'Silva | Sprint 1 | Individual shell tools#368
London | 26-SDC-Mar | Craig D'Silva | Sprint 1 | Individual shell tools#368craig-dsilva wants to merge 6 commits intoCodeYourFuture:mainfrom
Conversation
| # 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 No newline at end of file |
There was a problem hiding this comment.
- What will happen if this pattern faces a line looking like this:
DoctorImpostor: I'm real! - The task asks to output filenames only. What will happen our case, though?
| # 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.
Same here about the line like:
DoctorImpostor: lalalalala
| # 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 No newline at end of file |
There was a problem hiding this comment.
What will happen with the line like:
DoctorHouse: la la la
| # TODO: Write a command to output the total of adding together all players' first scores. | ||
| # Your output should be exactly the number 54. | ||
|
|
||
| awk '{ score += $3 } END { print score }' scores-table.txt No newline at end of file |
There was a problem hiding this comment.
good name for the variable name, self-descriptive, like
| # Your output should contain 3 lines, each with one word and one number on it. | ||
| # The first line should be "Ahmed 4". | ||
|
|
||
| awk '{if ($2 == "London") print $1, $NF}' scores-table.txt No newline at end of file |
| # 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 child-directory -t |
There was a problem hiding this comment.
Whilst it indeed produces what is asked, do we have a way explicitly tell ls to output list of names one per line?
| # 2 I was tempted to take a bite of it. | ||
| # 3 But this seemed like a bad idea... | ||
|
|
||
| cat ../helper-files/helper-3.txt -n No newline at end of file |
There was a problem hiding this comment.
it won't affect the result in this case, but just for clarity, it is better to pass options (i.e. -n) before filenames.
Typically the format of usage is
command [options] [filenames]
| # 4 I was tempted to take a bite of it. | ||
| # 5 But this seemed like a bad idea... | ||
|
|
||
| cat ../helper-files/*.txt -n No newline at end of file |
There was a problem hiding this comment.
it won't affect the result in this case, but just for clarity, it is better to pass options (i.e. -n) before filenames.
|
Overall good job, could you address my notes please? |
Learners, PR Template
Self checklist
Changelist
This is my coursework for Individual shell tools exercise.