I have a CSV file with lines like this:
AAA,A-name,num1,num2,num3
BBB,B-name,num1,num2,num3
CCC.DDD,C-name,num1,num2,num3
EEE.FFF.GGGG,E-name,num1,num2,num3
HHH.H-name,num1,num2,num3
...
Some lines have one identifier (like AAA); some have two (like CCC); some have three or more (like EEE). And some identifiers are not three characters. I need to remove all but the first identifier from each line of the line (such that the first period and anything that comes after it is deleted until the first comma is encountered), producing this:
AAA,A-name,num1,num2,num3
BBB,B-name,num1,num2,num3
CCC,C-name,num1,num2,num3
EEE,E-name,num1,num2,num3
HHH,H-name,num1,num2,num3
...
I’ve tried a few pattern-replace methods but am getting tripped up. Does anyone have the syntax I need?
Using perl
sed
and awk