Skip to content

Commit a726b2e

Browse files
committed
Add Count The Lines In A CSV Where A Column Is Empty as a Unix TIL
1 parent 7387786 commit a726b2e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1339 TILs and counting..._
13+
_1340 TILs and counting..._
1414

1515
---
1616

@@ -1257,6 +1257,7 @@ _1339 TILs and counting..._
12571257
- [Configure cd To Behave Like pushd In Zsh](unix/configure-cd-to-behave-like-pushd-in-zsh.md)
12581258
- [Copying File Contents To System Paste Buffer](unix/copying-file-contents-to-system-paste-buffer.md)
12591259
- [Copying Nested Directories With Ditto](unix/copying-nested-directories-with-ditto.md)
1260+
- [Count The Lines In A CSV Where A Column Is Empty](unix/count-the-lines-in-a-csv-where-a-column-is-empty.md)
12601261
- [Count The Number Of Matches In A Grep](unix/count-the-number-of-matches-in-a-grep.md)
12611262
- [Count The Number Of ripgrep Pattern Matches](unix/count-the-number-of-ripgrep-pattern-matches.md)
12621263
- [Create A File Descriptor with Process Substitution](unix/create-a-file-descriptor-with-process-substitution.md)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Count The Lines In A CSV Where A Column Is Empty
2+
3+
The [`xsv` utility](https://github.com/BurntSushi/xsv) is a fast way to analyze
4+
and work with CSV files from the command line.
5+
6+
With the `search` subcommand, I can seach for lines that match a pattern and
7+
even narrow that search to focus on a selected column.
8+
9+
For instance, to search for any lines where column 3 is empty:
10+
11+
```
12+
$ xsv search -s 3 '^$' data.csv
13+
```
14+
15+
The `-s 3` narrows the search to just column 3. The `'^$'` regex pattern
16+
matches on cells where there is the start character (`^`) and end character
17+
(`$`) with nothing in between, hence empty.
18+
19+
I can then pipe that to `wc -l` to get a count of the number of empty lines.
20+
21+
```
22+
$ xsv search -s 3 '^$' data.csv | wc -l
23+
```
24+
25+
See `xsv search --help` for more details.

0 commit comments

Comments
 (0)