diff --git a/book.md b/book.md index 35e1c418..93ba66aa 100644 --- a/book.md +++ b/book.md @@ -959,6 +959,8 @@ Sometimes material incentives are also very helpful, e.g. a promise 5$ gift card [day-337 unix](#day-337-unix) +[day-338 unix](#day-338-unix) + ## [DAY-0] The Computer All modern computers(laptops, phones, pc master race rgb monsters, etc) have somewhat similar components: Processor, Memory, Video Card, Disk and USB controller, WiFi card etc. Some of them are in one single chip and you cant even see them anymore, but they are there. For example there are chips that have Processor and Video Card together. The term for processor is actually CPU - Central processing unit, but we called it processors when we were kids and it kind of make sense, since it processes stuff. @@ -24500,4 +24502,22 @@ f.close() ``` +## [DAY-338] unix + +Make a program that counts the lines that are exactly 5 characters and start with 'h', use `nano` on the remote computer to edit the program from the previous day. + +``` +f = open("/etc/hidden/data.txt","r") +lines = f.readlines() +n = 0 +for l in lines: + if l.startswith("h"): + n += 1 +f.close() +print(n) +``` + +Now do the same with unix pipes, `cat /etc/hidden/data.txt | grep ^h | wc -l` + + diff --git a/examples/week-046/007.txt b/examples/week-046/007.txt new file mode 100644 index 00000000..7d8639a0 --- /dev/null +++ b/examples/week-046/007.txt @@ -0,0 +1,8 @@ +f = open("/etc/hidden/data.txt","r") +lines = f.readlines() +n = 0 +for l in lines: + if l.startswith("h"): + n += 1 +f.close() +print(n) diff --git a/toc.md b/toc.md index 2aa69fa6..a2f5559b 100644 --- a/toc.md +++ b/toc.md @@ -841,3 +841,5 @@ [day-336 unix](#day-336-unix) [day-337 unix](#day-337-unix) + +[day-338 unix](#day-338-unix)