I want to count the amount of lines in a CSV file. But only those with "<" at the beginning.
Asked
Active
Viewed 97 times
-2
-
Almost identical: [this question](https://stackoverflow.com/questions/40395018/counting-lines-starting-with-a-symbol), [this question](https://stackoverflow.com/questions/28899349/find-lines-starting-with-one-specific-character-and-ending-with-another-one), [this question](https://stackoverflow.com/questions/18489846/counting-lines-starting-with-a-certain-word)... – Benjamin W. Aug 04 '17 at 14:47
4 Answers
2
Use the awk, Luke:
$ cat file
foo
< this foo
not this foo <
< another of those foos
$ awk '/^</{c++}END{print c}' file
2

James Brown
- 36,089
- 7
- 43
- 59
0
You can get all the line containing '<' at the begining with grep '^<'
and count remaining line with wc -l
.
grep "^<" file.csv | wc -l

Frilox
- 815
- 2
- 13
- 24
-1
grep -E "^<" filename | wc -l
Use regular expressions with grep to check for < at the start of the line (^) and then pipe through wc -l to get number of lines.

Raman Sailopal
- 12,320
- 2
- 11
- 18