*Thursday, 18th June 2026 - 16:35 UTC+0100** --- It is possible to chain together multiple commands. Any number of commands, in fact. For example: ```bash cut -d , -f 1 seasonal/spring.csv | grep -v Date | head -n 10 ``` This chained command will do the following in order: 1. Select the first column from `seasonal/spring.csv`; 2. it will remove the header line containing the word "Date"; and 3. It will select the first 10 lines of the data itself. --- If I wished to count the records in a file, I could use the `wc` command. There are three commands that are useful that can be used with `wc`, though for printing, only one of these can be used at a time: - `-c`: prints the byte count - `-w`: prints the word count - `-l`: prints the newline counts --- But if I wanted to specify multiple files at once - such as grabbing the first column from multiple `.csv` files at once, I would do a command like this: ```bash cut -d , -f 1 seasonal/winter.csv seasonal/spring.csv seasonal/summer.csv seasonal/autumn.csv ``` But typing the names of multiple files over and over again can become a bit tiresome, and sooner or later it will inevitably lead to filenames being left out of filenames being repeated. Fortunately, wildcards like `*` can be used. With a wildcard, the above could be shortened thusly: ```bash cut -d , -f 1 seasonal/* ``` Or: ```bash cut -d , -f 1 seasonal/*.csv ``` An example of a wildcard in use would be in the command `head -n 3 seasonal/s*.csv` - which grabs the first three lines from every `.csv` file in the `seasonal` folder that starts with an S. --- --- `*` is not the only wildcard that can be used in the shell: - `?` matches a single character. For example, `201?.txt` would match `2017.txt` and `2018.txt`, but not `2017-01.txt` - `[...]` matches any one of the characters within the square brackets, so `201[78].txt` would match `2017.txt` and `2018.txt`, but not `2016.txt` - `{...}` matches any of the comma-separated patterns inside the curly brackers, so `{*.txt, *.csv}` would match any `.txt` or `.csv` file, but not any other file. --- --- A `sort` command does what it says on the tin, and by default it does this in an ascending alphabetical order. However, the `-n` flag can be used to sort numerically, `-r` can be used to reverse the order of the output, `-b` can be used to ignore leading blanks, and `-f` can be used to toggle case-insensitivity. A `sort` command can be appended to previously chained commands, and can have flags appended: ```bash cut -d , -f 2 seasonal/summer.csv | grep -v Tooth | sort -r ``` --- The `uniq` command can also be used with `sort`. What it does is remove duplicated lines. Specifically, adjacent duplicated lines. For example, if a file contained: ``` 2017-07-03 2017-08-03 2017-07-03 2017-08-03 ``` then `uniq` will produce: ``` 2017-07-03 2017-08-03 ``` But if all four of the lines were unique, then it would print all four. The command is built to work with very large files. If I wanted to write a pipeline that: 1. grabs the second column from `seasonal/winter.csv`, 2. removes the word "Tooth" from the output so that only tooth names are displayed, 3. sorts the outout so that all occurrences of a particular tooth name are adjacent; and 4. displays each tooth name once along with a count of how often it occurs ```bash cut -d , -f 2 seasonal/winter.csv | grep -v Tooth | sort | uniq -c ``` --- [[Upskilling|← Back to Upskilling]]