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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 12:39 PM
function help coolkid Shell Programming and Scripting 2 05-01-2008 02:47 PM
Log function Ernst Shell Programming and Scripting 17 03-19-2007 12:31 PM
Function within function (Recurance) chassis UNIX for Dummies Questions & Answers 2 09-19-2006 10:32 AM
How to convert the "select" function into a "poll" function rbolante High Level Programming 1 07-10-2001 11:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-13-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0