Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling functions in awk 2

Status
Not open for further replies.

jo90

Programmer
Jun 19, 2002
30
0
0
GB
Hi,

I have a file containing several awk functions, such as;

function1() {
BEGIN { FS = "'" }
print " " $2
}

can anyone tell me if this is correct, or how to call this from within a ksh script...

 
#!/bin/ksh
function1() {
echo "${1}" | nawk -F "'" '{print " " $2}'
}

var="foo'bar'xyz"

secondField=$(function1 "${var}") vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Thanks vlad,

Worked great. I can now source my file from script & call the function....

 
Jo90:

In addition to sourcing a file, if you're using korn/bash, you can use the autoload feature. Place these lines in /etc/profile, .profile, etc.

export FPATH=/usr/eds/functions # This is where autoloaded source resides
autoload function1 # alias for typeset -fu


Now, function1 isn't loaded until it's needed, and if you have a lot of other functions in the source file, they're never loaded unless required.

Regards,

Ed

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top