Here is my test.in file
Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Modify 10002 20002 30003 40004|
Script:
Remove.ksh
Quote:
cat test.in |
awk -F"\n" -v remove="$1" '{
input=$1;
remove_start=index(input,remove);
if (remove_start == 0) {
output = input;
} else {
if (remove_start == 1) {
output = substr(input,index(input,"|")+1);
} else {
output1 = substr(input,1,remove_start - 1);
output2 = substr(input,remove_start);
output = output1 substr(output2,index(output2,"|")+1);
}
}
printf "%s\n",output;
}'
This script to remove $1 which I type in:
$ cat test.in
Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Modify 10002 20002 30003 40004|
$ remove.ksh "Case Modify 10002"
Case Modify 10001 20002 30003 40004|Report Create 3417176211|
$
===========
How do I use this remove.ksh and write as a function so it can remove what I want
#!/bin/ksh
cd ./intermediate
cat out.log |
awk -F"|" '
function writeit()
{ printf "%s,%s\,%s\n\n",outputId,TempDateTime,outputAction;
outputAction = "";
return
} {
id=$1;
datetime=$2;
location=$3;
ani=$4;
ext=$5;
calLength=$6;
action = $7;
lastacct="";
............
if (action ~ /Modify/) { ## open if Modify
outputAction = action "|";
type = substr(action,1,index(action,"Modify")-2);
mainkey = substr(action,index(action,"Modify")+7,index(substr(action,index(action,"Modify")+7,20)," ")-1);
searchspec1 = type " " mainkey;
searchspec2 = type " Modify " mainkey;
searchspec3 = type " Access " mainkey;
if ((outputAction ~ searchspec1) || (outputAction ~ searchspec2)) {
} else if ((outputAction ~ searchspec3)) {
how to apply remove.ksh here to remove searchspec3 in outputAction
## add a funtion to call if outputAction contain searchspec3 then remove it from outputAction like
## outputAction ='Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Access 10001 10003 1004|Case Modify 10002 20002 30003 40004|'
## searchspec3 = 'Case Access 10001'
##then the outputAction ='Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Modify 10002 20002 30003 40004|'
[/color]
outputAction = outputAction action "|";
} else {
outputAction = outputAction action "|";
}
} else if (action ~ /Access/) {
type = substr(action,1,index(action,"Access")-2);
mainkey = substr(action,index(action,"Access")+7,index(substr(action,index(action,"Access")+7,20)," "));
searchspec1 = type mainkey;
searchspec2 = type "Modify " mainkey;
searchspec3 = type "Access " mainkey;
if ((outputAction ~ "searchspec1") || (outputAction ~ "searchspec2") || (outputAction ~ "searchspec3")) {
} else {
outputAction = outputAction action "|";
}
} else if (action ~ /CDxAcct/) {
acct = substr(action,9,10);
if (acct != lastacct) {
outputAction = outputAction "CDxAcct=" acct "|";
lastacct = acct;
}
} else if (action ~ /ID/) {
type = substr(action,1,index(action," ")-1);
mainkey = substr(action,index(action," ")+1,index(substr(action,index(action," ")+1,20)," ")-1);
searchspec1 = type " " mainkey;
searchspec2 = type "Modify " mainkey;
searchspec3 = type "Access " mainkey;
if (outputAction ~ searchspec1) {
} else if (outputAction ~ searchspec2) {
how to apply remove.ksh here to remove searchspec2 in outputAction
## add a funtion to call if outputAction contain searchspec2 then remove it from outputAction like
## outputAction ='Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Access 10001 10003 1004|Case Modify 10002 20002 30003 40004|'
## searchspec2 = 'Case Modify 10001'
##then the outputAction ='Report Create 3417176211|Case Access 10001 10003 1004|Case Modify 10002 20002 30003 40004|'
outputAction = outputAction action "|";
} else if (outputAction ~ searchspec3) {
how to apply remove.ksh here to remove searchspec3 in outputAction
## add a funtion to call if outputAction contain searchspec3 then remove it from outputAction like
## outputAction ='Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Access 10001 10003 1004|Case Modify 10002 20002 30003 40004|'
## searchspec3 = 'Case Access 10001'
##then the ='Case Modify 10001 20002 30003 40004|Report Create 3417176211|Case Modify 10002 20002 30003 40004|'
outputAction = outputAction action "|";
} else {
outputAction = outputAction action "|";
}
} else {
if (action == "CTI-Begin Call" || action == "CTI-CallTimer") {
} else {
outputAction = outputAction action "|";
}
}
}
} END {
writeit();
}'
=========================
out.log example