extract lines based on few conditions
Hi,
I need to extract lines based on some conditions as explained below:
File format details:
notes:
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, if any BBB's 5th column is blank then then script should provide us it's AAA line.
For. e.g, i have data for 3 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,,m
then the output must be
AAA,3,w,x,y,z
I could extract the line that is missing by below:
gawk -F"," '$1 == "BBB" && $5 == "" { print $0 }' /tmp/file
but clueless how to get the AAA-line of it.
Please advise.
Thanks
Prvn