Passing two files to awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing two files to awk
# 1  
Old 06-24-2010
Passing two files to awk

I want to pass the first file as input argument using -v then first get awk to go through mref then pert.txt

Code:
awk -v mref="reference.txt" -f ../../A-Scripts/convert-zv-zp.awk pert.txt

Code:
  BEGIN {
    Version = "V04"
    if ( !mref ) {
      usage(Version)
      print "ERROR: mref not specified"
      print ""
      exit 1
    }
    ARGV[ARGC++] = ARGV[ARGC-1]
    ARGV[1] = mref
    print ARGV[1]" "ARGV[2]
  }

# First time round, read the reference sound speed model
  FNR == NR {
    a[NR] = $2
    next
  }

# Calculate the fractional perturbation dc/c with respect to the reference
  {
    for (i = 2; i <= NF; ++i ) { $i = ($i - a[FNR]) / a[FNR] }
  }

# Print the depth and the corresponding dc/c
  { print }



---------- Post updated at 05:26 AM ---------- Previous update was at 04:51 AM ----------

Done. Solved it.
# 2  
Old 06-24-2010
hmm. Consider the FILENAME variable:
Code:
awk ' FILENAME=="mref" { process mref }
        FILENAME=="pert.txt" { process pert.txt } ' mref pert.txt
# more generally
f1="mref"
f2="pert.txt"
awk -v f1=$f1 -v f2=$f2 \
      ' FILENAME=="mref" { code to process mref }
        FILENAME=="pert.txt" { code to process pert.txt } '  $f1 $f2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

2. UNIX for Dummies Questions & Answers

Passing value in awk

Hi, I want to pass value of the variable i which is the radius in the following command in bash script: awk '{r=sqrt($2^2+$3^2+$4^2); if(r<=$i) print r }' input.txt It ignores $i in if command and print the whole range. I tried to replace $i with 6 and it worked. Would some one help me... (1 Reply)
Discussion started by: sxiong
1 Replies

3. Shell Programming and Scripting

Passing multiple files to awk for processing in bash script

Hi, I'm using awk command in bash script. I'm able to pass multiple files to awk for processing.The code i can use is as below(sample code) #!/bin/bash awk -F "," 'BEGIN { ... ... ... }' file1 file2 file3 In the above code i'm passing the file names manually and it is fine till my... (7 Replies)
Discussion started by: shree11
7 Replies

4. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

6. Shell Programming and Scripting

Passing multiple files to awk

Hi all, I have a load of files in the format e.g. a_1.out a_300.out a_20.out etc I would like to numeric sort them in ascending order by the number in the file name, then pass them into awk for manipulation. How do I do this? (8 Replies)
Discussion started by: jimjam
8 Replies

7. Shell Programming and Scripting

Passing non Awk Argument in Awk

Dear Conerned, I am facing a situation where i need to pass an argument which is non-awk variable like day=090319 awk '/TID:R/ && /TTIN:/' transaction.log I want to add this day variable like below awk '/TID:R$day/ && /TTIN:/' transaction.log But it is not working. :confused: (1 Reply)
Discussion started by: saifurshaon
1 Replies

8. Shell Programming and Scripting

Passing Value from awk to shell

I'm writting a script to calculate the total files and number of files that have been generated but not able to access the value of qwk variable in Shell. Please suggest.. Script :: cd /home/singhraa/tmp/scripts count=0 total=`wc -l hk_jobs.txt` #total number of files echo $total ... (3 Replies)
Discussion started by: raman1605
3 Replies

9. Shell Programming and Scripting

passing argument into awk

i'm trying to pass a numerical argument with function xyz to print specfic lines of filename, but my 'awk' syntax is incorrect. ie xyx 3 (prints the 3rd line, separated by ':' of filename) function xyz() { arg1=$1 cat filename | awk -F: -v x=$arg1 '{print $x}' } any ideas? (4 Replies)
Discussion started by: prkfriryce
4 Replies

10. Shell Programming and Scripting

Passing Variables to Awk

Hi I have a unix shell script with an awk statement. I would like to print some of the fields of an input file. However, I would like to print them dynamically, ie by passing the literal $1 $3 into the script to define the output. I have tried the following: variable1='$1' awk... (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question