awk routine help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk routine help
# 22  
Old 04-22-2009
The nawk script will be a function within a ksh script, called mynawk.

I will be calling mynawk with one of 3 arguments, either:

mynawk insert
mynawk update
mynawk delete.

For either insert or update I need the new.column printed
For the delete I need the old.column printed.

So I was thinking that type="update" should be type="$1" ( $1 meaning the first argument to the nawk routine ).

Then, based on the value of type ( either delete, update or insert ), the printf statement will know what to do.

I hope that explains it well enough. You've been very helpful and patient with me.

Thanks !!

Floyd
# 23  
Old 04-22-2009
Code:
printf("%c%s.%s%c%s", aT[i], (type=="update"||type="insert")?"new":"old", aN[i], aT[i],(i==FNR)?")" ORS:OFS)

# 24  
Old 04-22-2009
That's cool, I see that now.
But still I have no way of calling it with either an insert or an update or delete.

Here is what I'm trying to do. All of your code works great if I edit that last line and change it from update to insert to delete.
I don't want to do that. The script is calling a function (awkfunction) with 2 arguments. arg1 is the filename and arg2 is the string "update" or "insert" or "delete". Then whenever I call the function it will know whether to use old or new.



awkfunction () {
nawk '
{
all your awk code goes here
.....
.....
}' q="'" OFS=, type='$2' $1

}##end of awk function.


##shell script line that calles the awkfunction.
awkfunction filen insert




Thanks,
floyd
# 25  
Old 04-22-2009
Code:
awkfunction () {
nawk '
{
all your awk code goes here
.....
.....
}' q="'" OFS=, type="$2" "$1"

}##end of awk function.

# 26  
Old 04-22-2009
Oh yea sorry.
I tried that before with the double quotes and it didn't work, but then we didn't change the argument line to awk.

Hey thanks for all your help. It looks good.

SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to Parse An Inherited Command/Routine

I am am one of these people that it isn't good enough just to say, "Here, try this...". it is important for me to understand how and why something works (or doesn't work.) All that being said, I am trying to parse out a command that we use that was handed down to me by someone I can no longer... (3 Replies)
Discussion started by: he204035
3 Replies

2. Shell Programming and Scripting

PERL: Calling a sub routine from another module - help!!!

Hi, I am an occasional PERL user. I am trying to call a sub routine (passing parameters) in perl module from a driver .pl file. I have been "tinkering" for a while now and have confused myself. Could someone please look at the code below and spot where I am going wrong. testPerl.pl ... (0 Replies)
Discussion started by: chris01010
0 Replies

3. Shell Programming and Scripting

Paramerter pass for function(sub routine) need help

Hi, Please help me here while passing the paramert to fuction i am facing problem. i tryied passing 7 PARAMeter in side single quote,double quate even tried tild sign not working. how can assign it properly . usage () { typeset -i NumPARAMs=$1 typeset -i PARAM1=$2 typeset PARAM2=$3... (3 Replies)
Discussion started by: nitindreamz
3 Replies

4. Shell Programming and Scripting

Perl - Call a sub routine in a command

Hi all I have written a simple perl script that has different options i.e. myscript -l -p etc i have it so when it runs without any switches it runs a subroutine called nvrm_norm i want to be able to do a -p option and run pall -w -f and then called the subruotine pall is... (1 Reply)
Discussion started by: ab52
1 Replies

5. Shell Programming and Scripting

File exists routine

Hello experts, I need some help here.. I've written the following routine to check for existence of files. The routine does the following. It will look for a compressed ( .Z ) file and if it exists, then it will uncompress it, if it is already uncompressed, then it will just diplay a message... (9 Replies)
Discussion started by: kamathg
9 Replies

6. Shell Programming and Scripting

how to cp files to dir,using routine?

hi all, I wanted to know how we can copy files to dirs, through a routine and when the file and the dir are specified as parameters for that routine and explicitly called? Eg: suppose i want to copy file1 to /tmp then myproc() { . . } myproc /path/file1 /tmp/ These parameters when... (4 Replies)
Discussion started by: wrapster
4 Replies

7. UNIX for Advanced & Expert Users

how to cp files to dir,using routine?

hi all, I wanted to know how we can copy files to dirs, through a routine and when the file and the dir are specified as parameters for that routine and explicitly called? Eg: suppose i want to copy file1 to /tmp then myproc() { . . } myproc /path/file1 /tmp/ These parameters when... (1 Reply)
Discussion started by: wrapster
1 Replies

8. Shell Programming and Scripting

sub routine call

in windows machine... C:\2\test>perl -version This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) ------------------------------------------ what is the difference b\w subroutine calls: sub_routine_name("-----"); and ... (2 Replies)
Discussion started by: sekar sundaram
2 Replies

9. UNIX for Dummies Questions & Answers

Routine Task being a Solaris Administrator

Hi, What are routine task being a solaris administrator ? Thanks, Far (1 Reply)
Discussion started by: Far
1 Replies

10. Programming

Entry Points Routine

How do we pronounciate bdevsw and cdevsw Kernel resources ? I presume it as block or charcter device software table. Am I Correct in my assumption ? Thanks in advance. (9 Replies)
Discussion started by: S.P.Prasad
9 Replies
Login or Register to Ask a Question