Another.Chemist
Another.Chemist

Reputation: 2559

Finding lines without letters or numbers, only with commas, BASH

Good day to all,

I was wondering how to find the line number of a line with only commas. The only but is that I don't know how many commas have each line:

Input:

...
Total,Total,,,
,,,,
,,,,
Alemania,,1.00,,
...

Thanks in advance for any clue

Upvotes: 0

Views: 227

Answers (3)

Kent
Kent

Reputation: 195039

sed

sed -n '/^,\+$/=' file

awk

awk '/^,+$/&&$0=NR' file

Upvotes: 2

Cyrus
Cyrus

Reputation: 88573

With GNU sed:

sed -nr '/^,+$/=' file

Output:

2
3

Upvotes: 1

Cobra_Fast
Cobra_Fast

Reputation: 16061

You can do this with a single command:

egrep -n '^[,]+$' file

Line numbers will be prefixed.
Result with your provided four test lines:

2:,,,,
3:,,,,

Now, if you only want the line numbers, you can cut them easily:

egrep -n '^[,]+$' file | cut -d: -f1

Upvotes: 3

Related Questions