The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
function return array dophine Shell Programming and Scripting 6 05-06-2008 12:16 PM
Function to return an array of integer dwgi32 High Level Programming 2 11-20-2007 02:08 AM
need help with User Defined Function user_prady Shell Programming and Scripting 11 11-18-2007 08:51 PM
User defined signal 1 nitesh_raj AIX 0 01-29-2005 02:20 AM
Nawk user-defined function NewbieGirl Shell Programming and Scripting 1 06-20-2003 10:51 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 12-03-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Unhappy Return an array of strings from user defined function in awk

Hello Friends,

Is it possible to return an array from a user defined function in awk ?

example:
Code:
gawk '
BEGIN{}
{
   catch_line = my_function(i) 
   print catch_line[1]
   print catch_line[2]
   print catch_line[3]
}
function my_function(i)
{
 print "echo"
 line[1]= "awk"
 line[2]= "gawk"
 line[3]= "nawk"

 return line
}
' filename
Actually when I m returning a array from a function it shows me error.. Is it possible to return array ?

Pls help..

Thanks in advance..
  #2 (permalink)  
Old 12-03-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
no need to return

Hi,
I am not very sure about your req. But actually there is no need to return. The variable in your user-defined function will be recognized by awk. You can just deal with any variable in function, and out of function in awk other parts you can refer to it.

Just modify your code to follow:

gawk '
BEGIN{}
{
my_function(i)
print line[1]
print line[2]
print line[3]
}
function my_function(i)
{
print "echo"
line[1]= "awk"
line[2]= "gawk"
line[3]= "nawk"
}' filename
  #3 (permalink)  
Old 12-04-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by summer_cherry View Post
Hi,
I am not very sure about your req. But actually there is no need to return. The variable in your user-defined function will be recognized by awk. You can just deal with any variable in function, and out of function in awk other parts you can refer to it.

Just modify your code to follow:

gawk '
BEGIN{}
{
my_function(i)
print line[1]
print line[2]
print line[3]
}
function my_function(i)
{
print "echo"
line[1]= "awk"
line[2]= "gawk"
line[3]= "nawk"
}' filename
Yes Genious .. You are absolutely right...That is my requirment...

Thanks summer_cherry........
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 11:36 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