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
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 12:39 PM
create a thread from a returning function wolwy_pete High Level Programming 3 05-08-2008 04:48 AM
How to create SQRT function in catenate file ahjiefreak Shell Programming and Scripting 7 12-10-2007 12:31 PM
create thread C with JNI function with JAVA AUBERT HP-UX 0 08-06-2004 06:24 AM
How do I create desktop icons for the shell programs I create??? TRUEST UNIX Desktop for Dummies Questions & Answers 7 05-15-2002 12:40 PM

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-24-2007
kamel.seg kamel.seg is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 57
create function with awk

hi all,

i print four variable delimited by comma with awk :

awk -F "," '{print $1;$2;$3;$4}'
'
if $3=""
code ...
}
i want to extract this information from another file using another awk using the $1 printed

awk -v
{
code
}

but the problem i can't use two awk in the same code in shell script.


how can i create a function using the second awk and after that call it in the first awk traitement.

thanks
  #2 (permalink)  
Old 12-24-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
sample files, pls - and the desired result based on the samples.
  #3 (permalink)  
Old 12-24-2007
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
As mentioned an idea of what you are doing and have done would help. This example may help you in any case. It's a useless exercise but demonstrates what you *may* be wanting in principle. Tested only for gawk.
Code:
function getlines_from(fname,arr,p,fldlimit ,i) {

        while ( (getline < fname) > 0) {
                 for (i=0 ; i <= fldlimit ; i++) {
                      if (i == 0) {arr[p++] = " Next record group for working file " fname; i++}
                      arr[p++] = $i
                 }
        }
return p
}

BEGIN {
x=0
g=0
f=0
record[g]=""

       for (x=1 ; x < ARGC ; x++) {
           f = getlines_from(ARGV[x],record,g,6)
           g = f
           close(ARGV[x])
       }
       #for (f=1 ; f < g ; f++) {print f,record[f]}
}

{
  
  for (j=1 ; j <= 6 ; j++) {
       for (ab in record)
            if (record[ab] == $j) {printf "Match at %s, with indice %d for field $%d\n",record[ab],ab,j}  
       }
}
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 12:19 PM.


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