Hello Friend

I thought the best use of this cool github pages feature would be a TIL/Technical blog, welcome!

TIL (Today I Learned)

I want to fuzzy match on column 2, and look for anything that has “foo” in it. Well with awk, that is as simple as sending myfile.txt to awk using the following command

awk '$2 ~ /foo/' myfile.txt
It’s not the most intuative notation to read, but it is incredibly effective.

The second trick involves find a tool which, the more I use it the more I realize its powers extend far beyond simple directory searches. Using find it is possible to not only execute complex and useful search queries but to also execute commands on the found files/directories. find has a very powerful feature called execdir which allows you to execute a command or script from the context of the directory in which your find query found a match.

For example lets say we have a simple directory structure as below:

├── b
│   └── foo
├── c
│   └── foo
├── d
├── e
We want to find which directory contains a file called foo and then run a command on that file. To do so, we can use something like the following command
find -name "foo" -type f -execdir somecommand \;
Which will execute somecommand within the context of the directories containing the foo file. This is akin to manually cd‘ing into the directory containing the file and running the command. Insanely useful!

Which is best visualized by the following picture concurrency_vs_parallelism

We see that in the picture, task execution in the Concurrency example is sporadic. The idea is that modern (and even legacy systems) that are relegated to running multiple tasks on 1 core are able to work on a wide variety of tasks, jumping between them so quickly that it appears they are all ocurring at once. This is essentially also how Python handles multi threading.