Splitting a file based on a pattern

Hi All,

I am having a problem. I tried to extract the chunk of data and tried to fix I am not able to. Any help please

Basically I need to remove the for , values after K,

this is how it is now

A,,
B,
C,C,
D,D,
12/04/10,12/04/10,
K,1,1,1,1,0,3.0,
K,1,1,1,2,0,4.0,
K,1,1,2,1,0,3.0,
K,1,1,2,2,0,3.0,

And I want it to be like

A,,
B,
C,C,
D,D,
12/04/10,12/04/10,
K,1,1,1,0,3.0,
K,1,1,2,0,4.0,
K,1,2,1,0,3.0,
K,1,2,2,0,3.0,

I tried to split the file. But I think there will be a way to do that without splitting

grep K file >> newfile

and splitting the new file record by record and joining back

awk -F, -v f2rm=3 '$1=="K" && NF>=f2rm {for(i=f2rm;i<NF;i++) $i=$(i+1); NF--}1' OFS=, myFile

How about

awk -F, '/^K/ {sub ($3 FS, _)} 1' file
A,,
B,
C,C,
D,D,
12/04/10,12/04/10,
K,1,1,1,0,3.0,
K,1,1,2,0,4.0,
K,1,2,1,0,3.0,
K,1,2,2,0,3.0,
1 Like