File tree 2 files changed +27
-1
lines changed 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
10
10
11
11
For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
12
12
13
- _ 1339 TILs and counting..._
13
+ _ 1340 TILs and counting..._
14
14
15
15
---
16
16
@@ -1257,6 +1257,7 @@ _1339 TILs and counting..._
1257
1257
- [ Configure cd To Behave Like pushd In Zsh] ( unix/configure-cd-to-behave-like-pushd-in-zsh.md )
1258
1258
- [ Copying File Contents To System Paste Buffer] ( unix/copying-file-contents-to-system-paste-buffer.md )
1259
1259
- [ 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 )
1260
1261
- [ Count The Number Of Matches In A Grep] ( unix/count-the-number-of-matches-in-a-grep.md )
1261
1262
- [ Count The Number Of ripgrep Pattern Matches] ( unix/count-the-number-of-ripgrep-pattern-matches.md )
1262
1263
- [ Create A File Descriptor with Process Substitution] ( unix/create-a-file-descriptor-with-process-substitution.md )
Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments