Quantcast
Viewing latest article 33
Browse Latest Browse All 51

Answer by Louis Maddox for Counting commas in a line in bash

An example Python command you could run (since it's going to be installed on most modern shells) is:

python -c "import pathlib; print({l.count(',') for l in pathlib.Path('my_file.csv').read_text().splitlines()})"

This counts the number of commas per line, then makes a set from them (so if your lines all have the same number of commas in, you'll get a set with just that number in).


Viewing latest article 33
Browse Latest Browse All 51

Trending Articles