How to pass parameters to an awk file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass parameters to an awk file?
# 1  
Old 10-17-2008
Question How to pass parameters to an awk file?

I have an awk file where I need to pass a filename and a value as a parameter from a sh script. I need to know how to pass those values in the sh script and how to use the same in the awk file.

Thanks in advance!!!
Geetha
# 2  
Old 10-17-2008
Code:
SHELLVAR=BLA
awk -v awkvar=${SHELLVAR} '{print awkvar}'

If you enter "pass parameter awk" into Google for example, you get tons of useful hits Smilie
# 3  
Old 10-17-2008
Thanks zaxxon...

But I am getting error message as,

The file sample.awk,

if (( $14 < ( $13 / ARGV[1] )) && (( $14 > 50) || ( $13 >50 )))
{print}
}

And passing the parameter as,
awk -f sample.awk temp 10

where, temp is the file name and 10 is the value passed.

Now, I received an error message as,
awk: Cannot divide by zero.
The input line number is 1. The file is temp.
The source line number is 1.

Please let me know where I did wrong.

Thanks,
Geetha
# 4  
Old 10-17-2008
Ah ok, parameters - somehow it converted from my eyes to my brain to variables, nvm Smilie

Have a look here:
The GNU Awk User's Guide
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

To invoke pass parameters in Oracle file

Hi Guys, I am having a sql script file which does below operations ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE('&1','dd-MON-yyyy')) WITH TABLE &2 INCLUDING INDEXES; i need to pass variables in such a way that if i pass start date and end date as parameter , something like my... (2 Replies)
Discussion started by: rohit_shinez
2 Replies

2. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies

3. Emergency UNIX and Linux Support

Pass two parameters

Hi I have a batch file aaa.exe which needs two input parameters: Usually the command's format likes aaa 555 10000 But I want to use parameters to do it. aaa $1 $2 These two parameters come from a text file list.txt 41800497 41801375 41814783 41816135 41814930 41816135 41819987 41820843... (4 Replies)
Discussion started by: zhshqzyc
4 Replies

4. Shell Programming and Scripting

pass shell parameters to awk does not work

Why does this work for myfile in `find . -name "R*VER" -mtime +1` do SHELLVAR=`grep ^err $myfile || echo "No error"` ECHO $SHELLVAR done and outputs No error err ->BIST Login Fail 3922 err No error err ->IR Remote Key 1 3310 err But... (2 Replies)
Discussion started by: alan
2 Replies

5. Shell Programming and Scripting

Can't get shell parameters to pass properly to sqlplus

Gurus, The issue I'm having is that my Shell won't accept SQL parameters properly...... Here's they way I'm running it.... applmgr@ga006hds => sh CW_MigrationDeployScript.sh apps <appspwd> <SID> '01-JAN' '31-MAR' The process just hangs not submitting the SQL job... ... (3 Replies)
Discussion started by: WhoDatWhoDer
3 Replies

6. Shell Programming and Scripting

pass parameters from perl to csh scripts

I use csh a lot but I don't really write csh scripts. Now I have a need to implement a security check (written in perl; verify an user input security code) into a csh script. Here is the senario: #csh 1. call the perl script 2. if the perl script returns 'true', pass on; if the perl... (1 Reply)
Discussion started by: Julian16
1 Replies

7. Shell Programming and Scripting

need to pass parameters to working and tested awk script

I have a working and tested AWK script that removes duplicates from an input file and generates an output file without the duplicates. I had help from my other post to develop it: ... (3 Replies)
Discussion started by: script_op2a
3 Replies

8. Shell Programming and Scripting

want to pass parameters to awk script from shell script

Hello, I have this awk script that I want to execute by passing parameters through a shell script. I'm a little confused. This awk script removes duplicates from an input file. Ok, so I have a .sh file called rem_dups.sh #!/usr/bin/sh... (4 Replies)
Discussion started by: script_op2a
4 Replies

9. Shell Programming and Scripting

Pass parameters to function

Hi, for example I have this function: function get_param () { test=echo "some string" test2=echo "someother string" } I want to call this function and get test or test2 result, how do I do that ? Thank you (2 Replies)
Discussion started by: ktm
2 Replies

10. Shell Programming and Scripting

How to pass parameters transparently into a sub script

Hi, I am trying to write a script like this: #!/bin/ksh #script name: msgflow #The awk commands for Solaris and Linux are incompatible if ] then msgflow-solaris $* elif ] then msgflow-linux $* fi This script is shared by a file system which is visible to both... (3 Replies)
Discussion started by: danielnpu
3 Replies
Login or Register to Ask a Question