awk to print in a line

hi all,
i have text file with sample text

01                    
02        
 .. abc 
    
 .. def 
    
 .. xyz 
 .. x12 
03                    
04                    
    
    
 .. z123 
    
    
 .. x234 
    
    
 .. 2323

out put i am looking

01
02 abc,def,xyx,x12
03
04 z123,x234,2323

Thanks

What do the ".." stand for ?
1 word ?
more ?
Please post a full representative sample, not just a "kind of" sample.
The more precise a question is, the more precise the answer can be

sorry for that

i want the values between the numbers

anything starting with .. has come with its associated number above it as comma separated

for
01
02 (abc,def,xyz,x12)
03
04 (z123 ,x234,2323)

you mean your input files looks like :

01
02
02 abc
02 def
02 xyz
02 x12
03
04
04 z123
04 x234
04 2323

? or does it look another way ??

no sample i gave is exact

01
02
 abc

 def

 xyz
 x12
03
04


 z123


 x234




 2323

".." previous thing i removed

---------- Post updated at 01:59 PM ---------- Previous update was at 01:33 PM ----------

sorry for giving half info so far

my sample data looks like this

21
### W dcf 
               ### Wdcf HD 
             350                   
351                   
353                   
### abc Plus 
     36                    
###  abc 2 WEST 
         ###  abc xyzZONE     
###  abc NEXT            
###  abc  abcCASE WEST   
###  abc WEST 
           ###  abc WOMEN           
###  abcTIME         

so the out put i am looking is

21 (W dcf,Wdcf HD)
350
351
353 (abc Plus)
36 (abc 2 WEST,abc xyzZONE,abc NEXT,abc  abcCASE WEST,abc WEST,abcTIME )

This may help. Looks quite ugly. Others may give better sol.

 
sed -e 's/^\(.*\)\(###\)\(.*\)/\2\3/g' -e 's/^\([^#0-9]*\)\([0-9[0-9]*\)/\2/g' inputFile | awk '/^[0-9][0-9]*/{if(b=!""){print b;b="";}b=$0;next;} /###/{b=b ", " $0} END {if(b!="") print b}' | sed -e 's/###//g' -e 's/^\([0-9][0-9]*\),\(.*\)/\1 (\2 )/'

Would be ok if the output order doesn't matter :

sed 's/\s*###\s*//;s/^\s*//' infile | awk  '/^\s*$/{next}!/^[0-9][0-9]*/{B[x]=B[x]?B[x]","$0:$0}/^[0-9][0-9]*/{x=$1;A[$1]=$1" "}END{for(i in A)print A,(B)?"(":"",B,(B)?")":""}' OFS=''  
# sed 's/\s*###\s*//;s/^\s*//;s/\s\s*/ /g' infile | awk '/^[0-9][0-9]*/{x=$1;A[$1]=$1" "}!/^[0-9][0-9]*/{B[x]=B[x]?B[x]","$0:$0}END{for(i in A)print A,(B)?"(":"",B,(B)?")":""}' OFS=''
36 (abc 2 WEST ,abc xyzZONE ,abc NEXT ,abc abcCASE WEST ,abc WEST ,abc WOMEN ,abcTIME)
350
351
353 (abc Plus )
21 (W dcf ,Wdcf HD )
1 Like