Re: scripting help



mainak.sen@xxxxxxxxx wrote:
Hi,
I have two files (file 1 has one column and file 2 four columns), I
have to choose the rows of file 2 where column 2 & 3 of file 2 matches
with column 1 of file 1. Anybody has any idea?


To add to this with an example,

file 1 :
1_8
1_9
1_10
1_11


file 2 :
1 1_500 1_600 0.000 1.0 0.0 0.0
1 1_500 1_500 0.000 0.0 0.0 1.0
1 1_9 1_100 0.000 0.50000 0.50000 0.00000
1 1_9 1_200 0.000 0.50000 0.50000 0.00000
1 1_9 1_400 0.000 1.0 0.0 0.0
....
1 1_8 1_500 2.107 0.59766 0.40234 0.00000
1 1_8 1_9 2.107 0.89431 0.10569 0.00000
1 1_8 1_300 2.107 0.0 1.0 0.0


merge two files such that it will print
1 1_8 1_9 2.107 0.89431 0.10569 0.00000


i.e. the rows of file 2 where col.2 and col.3 matches with any two
entries in file 1
Any help would be extremely well appreciated.
Thanks


awk 'NR==FNR{arr[$1];next}($2 in arr)&&($3 in arr)' file1 file2

What if col2 and col3 of file2 have the same value and only match with one entry in file1?

Ed.
.



Relevant Pages

  • Re: scripting help
    ... Ed Morton wrote: ... What if col2 and col3 of file2 have the same value and only match with ... one entry in file1? ...
    (comp.unix.shell)
  • Re: simple ln question
    ... that makes it so the contents of file1 are the same as of file2, and if you change the contents of 1, the other ... prints the inode number for the file foobar. ...
    (Fedora)
  • RE: data conundrum
    ... in your spens you'll want to keep field names consistent. ... the specs will be the most tedious, but once theyr're done once they're done. ... in other words, you have file1, file2, file3..... ...
    (microsoft.public.access.externaldata)
  • RE: data conundrum
    ... let's say file1 looks like this: ... and let's say file2 looks like this: ... then you will probably have to create import specs for all 100 ... create from the .csv files) as opposed to using a form, ...
    (microsoft.public.access.externaldata)
  • Re: Need Help
    ... eg: file1, file2, file3 etc ... into, max 5-6, chunk files and then loading these chunk files into ...
    (comp.unix.shell)