Database Reference
In-Depth Information
We believe that creating reusable command-line tools makes you a more efficient and
productive data scientist in the long run. You gradually build up your own data sci‐
ence toolbox from which you can draw existing tools and apply it to new problems
you have previously encountered in a similar form. It requires practice in order to be
able to recognize the opportunity to turn a one-liner or existing code into a
command-line tool.
To turn a one-liner into a shell script, we need to use some shell scripting. We'll only
demonstrate the usefulness of a small subset of concepts from shell scripting. A com‐
plete course in shell scripting deserves a book of its own, and is therefore beyond the
scope of this one. If you want to dive deeper into shell scripting, we recommend Clas‐
sic Shell Scripting by Robbins & Beebe (2005).
Overview
In this chapter, you'll learn how to:
• Convert one-liners into shell scripts
• Make existing Python and R code part of the command line
Converting One-Liners into Shell Scripts
In this section, we're going to explain how to turn a one-liner into a reusable
command-line tool. Imagine that we have the following one-liner:
$ curl -s http://www.gutenberg.org/cache/epub/76/pg76.txt |
> tr '[:upper:]' '[:lower:]' |
> grep -oE '\w+' |
> sort |
> uniq -c |
> sort -nr |
> head -n 10
6441 and
5082 the
3666 i
3258 a
3022 to
2567 it
2086 t
2044 was
1847 he
1778 of
In short, as you may have guessed from the output, this one-liner returns the top ten
words of the ebook version of Adventures of Huckleberry Finn . It accomplishes this by:
Search WWH ::




Custom Search