Lines with comma

I have file which contains line with only comma and text separated by comma.
a.txt contain

a,ab,ac
,,
b,bc,bd
,,
,,
c,cd,ce

need to print only line 2, 4, and 5 because they only contain comma and no text.

I need an unix command to find out.

thanks in advance

Hello pranabpal,

In UNIX.com we encourage users to add 3 simple things.

1- Sample of Input in CODE TAGS.
2- Sample of expected output in CODE TAGS.
3- Most important thing, add efforts which you have put in order to solve your own problem in CODE TAGS.

Your question doesn't have any of them, so please EDIT your question and let us know then.

Thanks,
R. Singh

1 Like
grep ^, a.txt

^ beginning of the line
, a comma
So it prints all lines that start with a , i.e. if the 1st field is empty.
Perhaps you want to only print if all fields are empty?
BTW it is better to put the RegularExpression string in quotes, in order to avoid unwanted substitiutions from the shell : '^,'

... or anything BUT commaS

Wouldn't that require square brackets like '[^,]' ?

grep -E '^[ ,]'

@zouhair, could you please try following, considering that you want to print only those lines which have only , in them and nothing else an also they start and end with , only.

awk '/^,+$/'  Input_file

Thanks,
R. Singh

2 Likes