awk joining lines

Hello,
I'm trying to write a piece of code in awk, which should be able recognize by some regexps two lines and then join them together (maybe write them without \n would be enough, I don't know).. the thing is that every line in the file i'm working with starts with some number, for example:

1234: ... <found>
235: ... <found>
...
234: ... <success>
1234: ... <success>
...

The thing i need to do, is recognize two lines with the same number and on the first is regexp "<found>", on the second is "<success>". If these rules are fulfilled then join the lines together. I'm not pretty sure, but something tells me that associative arrays can be the solution, but I have no idea how to do it.
Thanks for ideas.

sort -n -t':' -k1  inputfile |
awk -F':'   '/<found>$/ {arr[$1]=$0}
               /<success>$/ { if ($1 in arr) {print arr[$1], $0; delete arr[$1]}}
               END {for (i in arr) {print arr} } ' inputfile > newfile

start with this, it assumes there are no orphan <success> rows - meaning if there is a <success> row there must exists a matching <found> row.

Keep all datas, not only export the found&success ones, and no worried about the orphan <found> or <success>

$ cat urfile
1234: ... <found>
235: ... <found>
...
236: ... <found>
234: ... <success>
235: ... <success>
1234: ... <success>
234: ... <success>

$ awk 'NR==FNR && !/success/ {a[$1]=$0;b[$1]=$NF} 
       NR>FNR && /success/ {$NF=b[$1] FS $NF; a[$1]=$0} 
       END { for (i in a) print a}' urfile urfile

1234: ... <found> <success>
234: ...  <success>
235: ... <found> <success>
236: ... <found>
...

Ok, the code from rdcwayx seems to work some way, but there's a thing that i don't understand, for exmaple in my file I have these lines:

5143 execve("/bin/ls", ["ls"], [/* 38 vars */] <unfinished ...>
5143 <... execve resumed> ) = 0

awk 'NR==FNR && !/resumed>/ {a[$1]=$0;b[$1]=$NF}
NR>FNR && /resumed>/ {$NF=b[$1] FS $NF; a[$1]=$0}
END { for (i in a) print a[i]}' urfile urfile

and I need to write this:

5143 execve("/bin/ls", ["ls"], [/* 38 vars */] <unfinished ...> <... execve resumed> ) = 0

but it only writes:

5143 <... execve resumed> ) = ...> 0

thank you for helping me, I very appreciate that :slight_smile:

please paste more real sample data to us, and the desired output.