I do not know, but the accepted answer does not give the indicated output for the channel "CBM.CLIENT", and all the answers are still intensive single-line. When the conversion is so complicated, I like the whole script, so I can see that.
#! /usr/bin/awk -f function Print() { OFS = "," print line["CHANNEL"], line["CONNAME"], line["USERID"], \ line["UOWLOG"], line["UOWLOGTI"] delete line } /Display Connection details[.]$/ { if( length(line) ) { Print() } next } $1 == "CHANNEL" { line[$1] = $2 if( 3 == split( $2, channel, /[.]/ ) ) { line[$1] = channel[2] "." channel[3] } next } { line[$1] = $2 } END { Print() }
The method is to build an associative array of all elements foo (bar), and output interesting bits in an obvious way. Regular expressions are simple and initial assumptions are relaxed: there is no dependence on the type of field and very little dependence on formatting.
He relies on a little preprocessing to put each key / value pair on his own line and post-processing to sort the output. Call as:
$ cat f.sh #! /bin/sh sed -E 's/^ +//; s/ +$//g; s/ +/\ /g' $1 | awk -F '[:()]' -f script.awk | sort -t, -k5 $ ./f.sh dat ABIS.CLIENT,101.54.151.80,malth,S0599315.LOG,11.06.38 APP.CLIENT,101.54.163.127,apsp,S0599317.LOG,11.07.29 SB.CLIENT,101.54.151.119,sbp,S0599317.LOG,11.07.38 CBM.CLIENT,101.54.163.37,machlth,S0599317.LOG,11.07.40
In the comments, OP mentions printing only lines that match a specific criterion. This is easy to add to this Print() function, and is easy to understand later.