Hi all,
I have a out.log file
CARR|02/26/2006 10:58:30.107|CDxAcct=1405157051
CARR|02/26/2006 11:11:30.107|CDxAcct=1405157051
CARR|02/26/2006 11:18:30.107|CDxAcct=7659579782
CARR|02/26/2006 11:28:30.107|CDxAcct=9534922327
CARR|02/26/2006 11:38:30.107|CDxAcct=9534922327
CARR|02/26/2006 11:49:30.107|CDxAcct=1405157067
LMWC|02/26/2006 11:59:28.307|CDxAcct=7659579780
LMWC|02/26/2006 12:01:28.307|Case Modify 10021 20024
LMWC|02/26/2006 12:11:28.307|Case Access 10021 20025
LMWC|02/26/2006 12:14:28.307|Case Modify 10022 20026
LMWC|02/26/2006 12:29:28.307|Case Modify 10023 20027
How do I write a script to get the result like this ??
CARR,02/26/2006 10:58:30.107,CDxAcct=1405157051|CDxAcct=7659579782|CDxAcct=9534922327|CDxAcct=1405157067
LMWC,02/26/2006 11:59:28.307,CDxAcct=7659579780|Case Modify 10021|Case Modify 10022|Case Modify 10023
Here is my bad code
#!/bin/ksh
cd /DAT/
cat out.log |
awk -F"|" '
function writeit()
{ printf "%s,%s\,%s\n\n",outputId,datetime,outputAction;
outputAction = "";
return
} {
id=$1;
datetime=$2;
action = $3;
lastacct = "";
if (outputId == ""){
outputId = id;
}
if (id != outputId ) {
printf "!!!! A: %s %s\n",outputId;
writeit();
outputId = id;
}
if (action ~ /CDxAcct/) {
acct = substr(action,9,10);
if (acct != lastacct) {
outputAction = outputAction "CDxAcct=" acct "|";
lastacct = acct;
} ## Remove duplicate acct like CDxAcct=1405157051|CDxAcct=1405157051|CDxAcct=7659579782
} else if (action ~ /Modify/) {
outputAction = action "|";
type = substr(action,1,index(action,"Modify")-2); #get Case
mainkey = substr(action,index(action,"Modify")+7,index(substr(action,index(action,"Modify")+7,20)," ")-1); #get number after Modify
searchspec1 = type " " mainkey;
searchspec2 = type " Modify " mainkey;
searchspec3 = type " Access " mainkey;
if ((outputAction ~ searchspec1) || (outputAction ~ searchspec2)) {
} else if ((outputAction ~ searchspec3)) {
# NEEDS FURTHER WORK To remove the Case Access XX from Case Modify XX
outputAction = outputAction action "|";
} else {
outputAction = outputAction action "|";
}
}
} END {
writeit();
}'
Thanks for your help.