Re: scripting help
- From: Janis Papanagnou <Janis_Papanagnou@xxxxxxxxxxx>
- Date: Fri, 27 Oct 2006 19:46:11 +0200
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
First read in data from file 1, then check whether the selected rows of
file 2 are in the stored data set.
awk 'NR==FNR {s[$1]} NR!=FNR && ($2 in s) && ($3 in s)' file1 file2
Janis
.
- Follow-Ups:
- Re: scripting help
- From: amrita . ray
- Re: scripting help
- References:
- scripting help
- From: mainak . sen
- scripting help
- Prev by Date: Re: scripting help
- Next by Date: Re: question about setenv
- Previous by thread: Re: scripting help
- Next by thread: Re: scripting help
- Index(es):