Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement using arrays

Status
Not open for further replies.

rhnaeco

Technical User
Aug 11, 2005
45
Hi, i need a bit of help sorting out my script:
awk '
BEGIN {
while (getline < "file1") {
cnt[$1]=$1
dep[$1]=$2
}
}
{
if (cnt[$1] = $1)
if ((dep[$1] < $2+0.4) && (dep[$1] > $2-0.4))
print $1, $2, dep[$1], $3, $4
}' file2 > file3

lines from file1:
486 -0.35 0.317856 88.95
486 -0.85 2.36172 88.95
486 -1.35 8.54376 88.95
486 -1.85 26.4533 88.95
486 -2.35 88.6047 88.95
lines from file2:
486 -1.47 38.1073 90.9
486 -1.97 34.7981 88.95
487 -1.47 37.7255 90.675
487 -1.97 34.4588 88.75
488 -1.47 35.6891 89.47

what i want the script to do is:

if cnt[$1] equals $1 in file2 (F2), then print $1(F2), $2(F2), $3(F1) if $2(F2) is within +/- 0.4 of $2(F2), $4


file3 (in theory- the same number of lines as file2):
486 -1.47 8.54376 90.9
486 -1.97 26.4533 88.95
487 -1.47 ?????? 90.675
487 -1.97 ?????? 88.75
488 -1.47 ?????? 89.47
thanks in advance

rhnaeco
 
Hello ,

I m very muech new to this

I have file
Col1 Col2
abc pqr
efg xyz

I want to loop through the no of rows in the file and print
$1 on one line and $2 on the next

 
thank you Annihilannic
i found another way around this, but any help learning this program is always useful!
only if you have the time...

thanks again
rhnaeco
 
rhnaeco said:
$3(F1) if $2(F2) is within +/- 0.4 of $2(F2)

This part of your requirements is broken... $2(F2) will always be the same as $2(F2), let alone within 0.4 of it?

The other problem is that your cnt array will only ever have one member, because it is indexed by $1, which in your sample data has the same value on every line.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top