Q: Using Sed to extract data between < and > I have been provided the following sed command :
sed "s/^[^<]*<//;s/>[^<]*</,/g;s/>.*$//" CmcComRouting.log > PTChuteLog2.log

which works well to extract the data between the < and >.
160218 003034 0053 DE(N) RoutingIfCmc1.cmccom TX: Tlg=<tlgNo=<0014: ItemIdTlg>, length=<5>, cmcIndex=<942>, itemId=<13983804>, globalId=<13983804>>

But, what I would like to keep is the first half of the date and time sections:
160218 003034

Is there a way to use sed, grep or awk to do this to keep the first part, extract everything between the <> and put a comma between each field?

A: I have modified the command as follows:
$ sed 's/^\([0-9]* [0-9]* \)[^<]*<[^<]*</\1/;s/>[^>]*>[^>]*$//;s/>[^<]*</,/g' <<< "$var"
160218 003034 0014: ItemIdTlg,5,942,13983804,13983804

Firstly, the command as it was did not properly extract between <>. There is a pair of angle brackets around all other pairs, and the previous command behaved like this: from data like
xyz <something<a>blah<b>something> xyz

It would extract
something<a,b

To fix that, I've modified the first command to
s/^[^<]*<[^<]*<//

and, correspondingly the last command to
s/>[^>]*>[^>]*$//

The last command actually worked as is, but with a greedy match – this one is more controlled.
To extract the first to sequences of numbers, the first command has to capture them:
s/^\([0-9]* [0-9]* \)[^<]*<[^<]*</\1/

So, all in all, you have (a bit more readable)
sed 's/^\([0-9]* [0-9]* \)[^<]*<[^<]*</\1/
s/>[^>]*>[^>]*$//
s/>[^<]*</,/g' CmcComRouting.log > PTChuteLog2.log


A: This MAY be what you want:
$ cat tst.awk
{
    printf "%s,%s", $1, $2
    while ( match($0,/<[^<>]+>/) ) {
        printf ",%s", substr($0,RSTART+1,RLENGTH-2)
        $0 = substr($0,RSTART+RLENGTH)
    }
    print ""
}

$ awk -f tst.awk file
160218,003034,0014: ItemIdTlg,5,942,13983804,13983804

but without you showing us the expected output in your question we're just guessing.
