Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # In a CSV file, how to count all lines matching a condition?
- Following on our CSV file processing series, here is how to count the number of lines that match a condition.
- We’ll keep using `awk`. Here is the command to run:
- ```bash
- awk -F, '{if ($5 == "foo") count+=1} END {print count}'
- ```
- Easy enough, `-F,` tells each line use the comma to delimit each column.
- Then for each line in the file, check if the 5th column is equal to `foo`. If true then increment the `count` variable by 1.
- When done processing all lines, just print `count`.
- Voila, you’re ready to process GB of CSV files without killing your spreadsheet software or writing a single line of code!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement