awk function from shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk function from shell
# 1  
Old 08-12-2008
awk function from shell

Hi all.
I have a selection of awk functions which I have written and tested in a main awk program.
From the command line I use nawk -f function -f main to run main and call my functions from within it.
I now wish to use these awk function again but want to call them from inside an awk section of a shell script. I am wondering whether this is possible and if so how i might go about it.

Code:
myfuntion(data){
some data validation
returns 0 or 1
}

Code:
#!/bin/sh
cat somefile.csv| nawk ' 
valid=myfunction(data)

Thanks for your help ppl
# 2  
Old 08-13-2008
Something like this seems to work, at least with mawk on Ubuntu.

Code:
mawk -f func.awk -f - somefile.csv <<'HERE'
valid=myfunction(data)
HERE

As noted elsewhere, awk doesn't need to have data piped into it by cat, and indeed, in this case, it wouldn't work, since the script is supplied as standard input, not the data.
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

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

3. 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

4. Shell Programming and Scripting

Call shell script function from awk script

hi everyone i am trying to do this bash> cat abc.sh deepak() { echo Deepak } deepak bash>./abc.sh Deepak so it is giving me write simply i created a func and it worked now i modified it like this way bash> cat abc.sh (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

5. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
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

shell function, system, awk

Hi all, I am calling a shell function within awk using system. I am struggling to get my expected output: #!/bin/sh set -o nounset BEG=44 END=55 shfun() { echo "1|2|3" } export -f shfun typeset -F > /dev/null awk 'BEGIN {OFS="|"; print "'"$BEG"'",system( "shfun"... (5 Replies)
Discussion started by: jkl_jkl
5 Replies

9. 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

10. Shell Programming and Scripting

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 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... (0 Replies)
Discussion started by: sabercats
0 Replies
Login or Register to Ask a Question