awk with function ?? please, help :(


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk with function ?? please, help :(
# 1  
Old 03-13-2006
awk with function ?? please, help :(

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

awk function

hi, I have used awk command to delimit my variable. But this that not worked. Could you please let me know what need to be changed in my awk command Input: home/unix>cat test.txt DAILY.JOB CHENNAI,8388 DAILY.JOB BANGLORE,3848 DAILY.JOB TRICHY,9489 DAILY.JOB TIRUPUR,8409 code ... (9 Replies)
Discussion started by: arun888
9 Replies

3. Shell Programming and Scripting

System function in awk

Hello Friends, I have written a script like below, I aimed to move some CDR files (call data record) whose the last field is "1" (NF=1 ) from a spesific directory to a new directory Field Seperator is pipe. If the directory does not exitst i should create it. I will give the script two... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. Shell Programming and Scripting

awk function

Hi all, I need to have informations in a URL : https://www.autolib.eu/stations/ Valors I need are in bold: {"charging_status": "nonexistent", "rental_status": "future", "subscription_status": "nonexistent", "station_id": 791, "address": "10 rue de Rome, 93110 Rosny-sous-Bois", "lat":... (3 Replies)
Discussion started by: roulitto
3 Replies

5. Shell Programming and Scripting

Awk-using group function

Hi, I have file with below format and sample data - File is pipe delimited Col1|col2|Account|Bal1|Bal2 1|2|1|10|5 1|2|2|10|2 1|3|3|10|3 I want output as SUM|1|2|2|20|7 SUM|1|3|1|10|3 Can anyone give me awk command (4 Replies)
Discussion started by: sanranad
4 Replies

6. Shell Programming and Scripting

AWK Function syntax

Hi, I would like to know what is the correct syntax to perform a function in awk. Although I have seen several examples, not get it to work, this is what I'm trying: #!/bin/bash awk function multi (number) { return number * 3 } print multi (4)Thanks (2 Replies)
Discussion started by: Godie
2 Replies

7. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

8. Shell Programming and Scripting

MODE function in awk

Hello, Can someone pls help me with some statistical calculation in awk In excel there is a statistical function called "Mode". How Mode works: MODE returns the most frequently occurring, or repetitive, value in array or range. Eg if we have 5 numbers in 5 different columns... (12 Replies)
Discussion started by: Needhelp2
12 Replies

9. Shell Programming and Scripting

external function in awk

Hi all, I have a basic doubt. Is there any way to use external functions (i.e. functions not defined in AWK), in AWK. I have a shell script in which I'm using a AWK snippet. In this snippet I'm calling a function defined in the shell script. But the AWK snippet is not working. I figured that... (5 Replies)
Discussion started by: kamel.seg
5 Replies

10. Shell Programming and Scripting

Help with the function awk

Hi I am trying to create a modify a txt file via a sh script and I'm not sure how to do it. I have this: data1a#data2a#data3aµ data1b#data2b#data3bµ data1c#data2c#data3cµ and I want to have this (more or less) data1a data2a data3a data1b data2b data3b data1c data2c data3c I know... (5 Replies)
Discussion started by: Morgwen
5 Replies
Login or Register to Ask a Question