conditional extracting
Hi,
I need to extract lines based on some conditions as explained below:
File format details:
1. each set starts with AAA only
2. number of columns is fixed
3. number of rows per set may vary (as one set is upto DDD - 4 rows)
Now, i need to extract only the lines starting with AAA and BBB only. The condition is to pick AAA and BBB if and only if both exist in the same data set.
For. e.g, i have data for 4 sets and file has the below:
AAA,1,a,b,c,d
CCC,1,p,q,r,s
BBB,1,j,k,l,m
AAA,2,j,k,l,m
BBB,2,a,b,c,d
AAA,3,w,x,y,z
CCC,3,p,q,r,s
DDD,3,a,b,c,d
BBB,3,j,k,l,m
AAA,4,w,x,y,z
CCC,4,p,q,r,s
then the output must be
AAA,1,a,b,c,d
BBB,1,j,k,l,m
AAA,2,j,k,l,m
BBB,2,a,b,c,d
AAA,3,w,x,y,z
BBB,3,j,k,l,m
(Pl note there is no 4th data set in the output as 4th data set has no BBB)
Please advise.
Thanks
Prvn