create function with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create function with awk
# 1  
Old 12-24-2007
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  
Old 12-24-2007
sample files, pls - and the desired result based on the samples.
# 3  
Old 12-24-2007
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}  
       }
}

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

Automaticaly create function based off user input

I am trying to create a bash script that will create new function by using the user input. The below will create the necessary files in the correct format, however when it comes to the # create function I am at a loss. If the name entered was NEWNAME and the genes were GENE1,GENE2 then two files... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

Create function

I would like to make a perl function , this function could send mail via SMTP and also could import a text file into mail content , that mean I have a text file , want to use this function to send mail via SMTP , the mail content is the text file , would advise how to write this script ? thanks (1 Reply)
Discussion started by: ust3
1 Replies

5. Shell Programming and Scripting

How to create .txt file by using function?

My Calling script is like below: for file in `echo $LIST_OF_FILES` --listing filenames eg, xyz_meta_20110501_00000789.tar do file_name=`basename $file` <call a function to create .txt file in below format> done Want to generate a .txt file that contains below data in ksh: ... (3 Replies)
Discussion started by: vedanta
3 Replies

6. Shell Programming and Scripting

How create function valid birthday format dd-mm-yyyy

I write a small shell script create Payroll System my trouble is valid format birthday dd-mm-yyyy when you enter birthday if your value enter not match with format dd-mm-yyyy system will display "Fail Format Please re-enter Birthday with format dd-mm-yyyy" but i don't know how create function... (3 Replies)
Discussion started by: kency
3 Replies

7. UNIX for Dummies Questions & Answers

How to create alias for a function

Hi, In Unix (AIX/LINUX) how do we create a alias for a UNIX shell function? Please help me with that. Thanks!! (2 Replies)
Discussion started by: neeto
2 Replies

8. Programming

create a thread from a returning function

hi all, my requirement is to create a thread by calling another function. i.e i dont call pthread_create directly from main, but by calling another function (createThd - below ), from main. Example: void *thread_function(void *arg) { /* thread function */ int i; rc =... (3 Replies)
Discussion started by: wolwy_pete
3 Replies

9. Shell Programming and Scripting

How to create SQRT function in catenate file

HI, I have a file which i catenate and using the fields in the file, I would like to get sqrt of it. I tried to man the function but it normally would need an echo as well as bc. What I am intending to find out is catenate a file where let say cat a.txt| awk ' { t= h*($3+$2); t=... (7 Replies)
Discussion started by: ahjiefreak
7 Replies

10. HP-UX

create thread C with JNI function with JAVA

Hello, J create a thread C with a JNI function via JAVA. J have the following message (but not in each time): Someone has an idea ? Thank. Unexpected Signal : 4 occurred at PC=0x78C103E0 Function= Library=(N/A) NOTE: We are unable to locate the function name... (0 Replies)
Discussion started by: AUBERT
0 Replies
Login or Register to Ask a Question