I am trying to pass max as a sommand line argument when I call awk.
Made the modification in the BEGIN but it is not working
I'm getting an error as below:
awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory)
Somehow it is reading 40 and interpreting it as a file.
# 1: Absolute value of a number
function abs(val) {
return val > 0 ? val : -val
}
# 2: Read file twice, set maximum S-R distance
BEGIN {
# ARGV[ARGC++] = ARGV[ARGC-1]
print "0." ARGV[0]
print "1." ARGV[1]
print "2." ARGV[2]
print ""
ARGV[ARGC++] = ARGV[2]
ARGV[ARGC-2] = ARGV[ARGC-3]
max = 40
print ARGC
print "0." ARGV[0]
print "1." ARGV[1]
print "2." ARGV[2]
print "3." ARGV[3]
}
# 3: First time round, store source location
FNR == NR {
/>/ && idx[FNR] = ++i
$2 || val = $1
next
}
# 4: Second time round, get source location
FNR in idx {
v = val[idx[FNR]]
}
# 5: Calculate S-R distance
{ !/>/ && dist = abs( $1 - v ) }
# 6: Print only if S-R distance less than max, create third column
# For the print statement can also use { OFS = ""; print $0, $2; OFS = " " }
/>/ || dist < max && NF == 2 { sub(/[ \t]+$/, ""); print }