The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
Stumble this Post!
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-10-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,426
Stumble this Post!
Not sure that I understand what you want. But maybe this does it...
Code:
#! /usr/bin/ksh
IFS="|"
first=1
exec < out.log
while read  name field2 field3; do
        if ((first)) ; then
                first=0
                oldname=$name
                output="${name}${field2}|${field3}"
        elif [[ $name != $oldname ]] ; then
                echo "$output"
                output="${name}${field2}|${field3}"
                oldname=$name
        else
                output="${output}|${field3}"
        fi

done
echo "$output"
exit 0
Reply With Quote
  #3 (permalink)  
Old 03-10-2006
Registered User
 

Join Date: Jul 2005
Posts: 137
Stumble this Post!
Ruby:
Code:
gets(nil).scan( /^(.*?)\|(.*?)\|(.*\n(?:\1.*\n)*)/ ){|b|
  b.last.gsub!( /^.*(?=\|)/,"" ).gsub!( /\n/,"" )
  puts b.join(",")
}
Reply With Quote
  #4 (permalink)  
Old 03-10-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
Stumble this Post!
Oh cool, I learn another way, I will post you my code when I am done
Thanks,
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0