The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-18-2008
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
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