SED command problem

hi frnds,
my data file goes like this

sessioj123 ffl
sfootxt
sgsggs TARG ROW
aaa :123
bbb : 145
ccc: 669
vvv: 777
)

my output should be 123,145,669,777.

we can identify the data block using the keywor TARG ROW and ).

Plz help how to implement using SED commands in shell script

i should loop through the file friend

Use CODE-tags when posting code, data or logs to enhance readability and to preserve formatting like indention etc.,ty.

sed -n -e 's/[^:]*: *\([0-9]*\)$/\1/p' infile| sed -e :a -e 'N; s/\n/,/; ta'
123,145,669,777

you put spaces around colon. mistakenly or it can happen??

if "sgsggs TARG ROW" is your third row always and ")" is the last row then

try this:

tail +4 file | sed '$d' | awk 'BEGIN { FS= ":";ORS = ","} { print $2} END { print "\n"}' 

Hi Anchal,

the file has n lot of lines in it. its log file. we should search the word TARG ROW and ")" and hv take out the values resides between these search patern.

in second,3rd,4th.. occurances , the number of values/lines between both the search pattern getting vary

the SED sommsnd should automatically search the both the pattern one by one and pick the values and formate the value row by row like this

Just a example output
123,235,533,343
234,445,3434,343
232,242,23,123,00

Must you use sed?

awk -F'[ :]' '/\)/ { o=s=0; print "" }
              s { printf("%s%s", o ? "," : "", $NF); o=1 }
              /TARG ROW/ { s=1 }' filename

Good question Cambridge.

@Gopal_Engg:
Did you try out my sed solution?
I gave you a warning for not using CODE tags even I asked for them in my post. Please start using CODE tags accordingly in your future posts, ty.

sed -e '1,/TARG ROW/d' -e '/^)$/,$d' -e 's/.*: *//' yourfile | tr '\n' ','

Thanks Jerry .. ur reply solved my problem

sed -n '/[a-z][a-z]* *: *[0-9][0-9]*/{H;}
/)/{x;s/\n/,/g;s/,[^:]*:/,/g;s/^,//;p;}'