You should learn the UNIX tools.
The UNIX operating system consists of dozens of small, simple commands. Each of these commands is a program in its own right. Almost all of them can take a stream of data as an input and deliver a stream of data as an output, performing different kinds of data processing transformation.
By chaining together a few of these commands, you can accomplish a lot. Similar to building blocks, you can assemble them in endless ways. The output of one command becomes the input for the next, using the pipe symbol to connect them.
For example, suppose you have a file with a list of names, and you want to find out what the top 3 most common first names are in the file. The string of UNIX commands could look like this:
cat names.txt | cut -f1 -d' '| sort|uniq -c| sort -nr| head -3
Here is the breakdown of these commands:
- cat names.txt opens the names.txt file and sends it to standard output.
- cut -f1 -d’ ‘strips out everything but the first field, using a space as the delimiter. The output now has only the first names.
- sort will rearrange the names in order.
- uniq -c gives a list of the unique names and their count.
- sort -nr sorts again, this time using treating the first field as a number, and sorts in reverse (largest number first).
- head -3 stops the output after 3 rows.
Some of the more obscure UNIX commands can do amazing things. One should explore them and learn their capabilities.
You can extend these ideas to programming as well. Take the objects returned from one class’s methods and use them as inputs to methods in another class.