London | 26-SDC-March | Zobeir Rigi | Sprint 1 | Individual shell tools#400
London | 26-SDC-March | Zobeir Rigi | Sprint 1 | Individual shell tools#400Zobeir-Rigi wants to merge 6 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
|
||
| # TODO: Write a command to output the contents of the helper-1.txt file inside the helper-files directory to the terminal. | ||
| # The output of this command should be "Once upon a time...". | ||
| cd helper-files |
There was a problem hiding this comment.
do we have the helper-files folder inside the cat directory?
There was a problem hiding this comment.
No, it's in a different folder called the helper-files directory.
| # It looked delicious. | ||
| # I was tempted to take a bite of it. | ||
| # But this seemed like a bad idea... | ||
| cat *.txt |
There was a problem hiding this comment.
do we have txt files inside cat directory?
There was a problem hiding this comment.
No, that's why I cd to the helper-files directory first.
| # I was tempted to take a bite of it. | ||
| # But this seemed like a bad idea... | ||
| cat *.txt | ||
| pwd should be in the helper-files directory |
There was a problem hiding this comment.
what will happen with this line during script execution?
There was a problem hiding this comment.
cat is a commond to print file contents
pwd, I'm just making sure to be in the related directory.
| # 1 It looked delicious. | ||
| # 2 I was tempted to take a bite of it. | ||
| # 3 But this seemed like a bad idea... | ||
| cat -n helper-3.txt No newline at end of file |
There was a problem hiding this comment.
Do we have helper-3.txt file inside the directory?
There was a problem hiding this comment.
All txt files are in the helper-files directory.
| # 3 It looked delicious. | ||
| # 4 I was tempted to take a bite of it. | ||
| # 5 But this seemed like a bad idea... | ||
| cat * | nl No newline at end of file |
There was a problem hiding this comment.
What is the path to the folder we want to work with?
There was a problem hiding this comment.
helper-files directory, which is in the individual-shell-tools folder.
|
|
||
| # TODO: Write a command to output every line in dialogue.txt that contains the word Doctor (regardless of case). | ||
| # The output should contain 9 lines. | ||
| grep -ci "Doctor" dialogue.txt No newline at end of file |
There was a problem hiding this comment.
What does -c param stand for in this case?
There was a problem hiding this comment.
To count the number of lines, which we don't need to count here, thanks for catching this. only -i is enough.
|
|
||
| # 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" *.txt No newline at end of file |
There was a problem hiding this comment.
What will happen if we meet a line of a patient, for example, saying something like "Hello, Doctor!"
There was a problem hiding this comment.
It will also be counted, and I should use this commond instead ===> grep -il "^Doctor:" *.txt
So, making sure started with the Doctor
|
|
||
| # 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.
What will happen if we meet a line of a patient, for example, saying something like "Hello, Doctor!"
There was a problem hiding this comment.
again it should be "^Doctor:" *.txt
| # Your output should contain 3 lines, each with one word and one number on it. | ||
| # The first line should be "Ahmed 4". | ||
| awk '$2=="London" {print $1, $NF}' scores-table.txt | ||
| #$NF → last column No newline at end of file |
There was a problem hiding this comment.
Like for the comment explaining the intention
| # Your output should contain 6 lines, each with one word and one number on it. | ||
| # The first line should be "Ahmed 3". | ||
| awk '{print $1, NF-2}' scores-table.txt | ||
| # NF = total number of fields in the line, NF - 2 = removes name + city No newline at end of file |
|
Could you address my comments please, most of them are around the same issue with paths. |
Summary
Implemented individual shell tool exercises, including ls, cat, wc, grep, sed, and awk. Practised file navigation and text processing using standard Unix commands.
Checklist