diff --git a/README.md b/README.md index 9104666..785ce9e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1339 TILs and counting..._ +_1340 TILs and counting..._ --- @@ -1257,6 +1257,7 @@ _1339 TILs and counting..._ - [Configure cd To Behave Like pushd In Zsh](unix/configure-cd-to-behave-like-pushd-in-zsh.md) - [Copying File Contents To System Paste Buffer](unix/copying-file-contents-to-system-paste-buffer.md) - [Copying Nested Directories With Ditto](unix/copying-nested-directories-with-ditto.md) +- [Count The Lines In A CSV Where A Column Is Empty](unix/count-the-lines-in-a-csv-where-a-column-is-empty.md) - [Count The Number Of Matches In A Grep](unix/count-the-number-of-matches-in-a-grep.md) - [Count The Number Of ripgrep Pattern Matches](unix/count-the-number-of-ripgrep-pattern-matches.md) - [Create A File Descriptor with Process Substitution](unix/create-a-file-descriptor-with-process-substitution.md) diff --git a/unix/count-the-lines-in-a-csv-where-a-column-is-empty.md b/unix/count-the-lines-in-a-csv-where-a-column-is-empty.md new file mode 100644 index 0000000..753b7ab --- /dev/null +++ b/unix/count-the-lines-in-a-csv-where-a-column-is-empty.md @@ -0,0 +1,25 @@ +# Count The Lines In A CSV Where A Column Is Empty + +The [`xsv` utility](https://github.com/BurntSushi/xsv) is a fast way to analyze +and work with CSV files from the command line. + +With the `search` subcommand, I can seach for lines that match a pattern and +even narrow that search to focus on a selected column. + +For instance, to search for any lines where column 3 is empty: + +``` +$ xsv search -s 3 '^$' data.csv +``` + +The `-s 3` narrows the search to just column 3. The `'^$'` regex pattern +matches on cells where there is the start character (`^`) and end character +(`$`) with nothing in between, hence empty. + +I can then pipe that to `wc -l` to get a count of the number of empty lines. + +``` +$ xsv search -s 3 '^$' data.csv | wc -l +``` + +See `xsv search --help` for more details.