![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to remove duplicate lines | fredao | Shell Programming and Scripting | 3 | 12-13-2006 08:51 AM |
| Remove duplicate phrase | kesu2k | Shell Programming and Scripting | 6 | 10-17-2006 01:34 PM |
| Remove duplicate | sabercats | Shell Programming and Scripting | 2 | 03-31-2006 09:35 AM |
| Remove Duplicate line | Student37 | UNIX for Dummies Questions & Answers | 1 | 02-22-2005 11:00 AM |
| remove duplicate | kazanoova2 | Shell Programming and Scripting | 4 | 04-11-2004 09:35 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Remove duplicate ???
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. Last edited by sabercats; 03-10-2006 at 01:15 PM. |
| Forum Sponsor | ||
|
|