Matching and retreiving numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching and retreiving numbers
# 1  
Old 01-14-2013
Linux Matching and retreiving numbers

Hi,

I have one file 1.txt with one field consist of following Ids (shortlisted 10 but showing 3 here):
Code:
00052
00184
00607

and then second file 2.txt with three fields (very big file):
Code:
00052	00184	12.73062
00052	00598	13.51205
00052	00599	13.92554
00052	00600	13.73358
00052	00601	13.64979
00052	00602	13.67168
00052	00603	13.11602
00052	00607	13.25308
00184	00602	 9.99894
00184	00603	 9.79437
00184	00604	 9.86195
00184	00607	 9.58066

I wish to retreive the value where IDs from 1.txt matches as per 2.txt. One more thing, there are no repetitive rows in 2.txt, for example, for 00184 and 00607, only following 1st row is present and not 2nd.
00184 00607 9.58066
00607 00184 9.58066

Required output:
Code:
00052	00184	12.73062
00052	00607	13.25308
00184	00607	 9.58066

Thanks.
# 2  
Old 01-14-2013
Try:
Code:
awk 'NR==FNR{A[$1]; next} $1 in A && $2 in A' 1.txt 2.txt

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-14-2013
Thanks. It working. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk decimal point numbers matching

Hi All, Can some one help me in identifying the significance of character "$" ,Which is playing critical role in matching decimal point numbers as below. $ echo "01#.01"|awk '{if ($0 ~ /^+(\.*)?$/) print}' $ echo "01#.01"|awk '{if ($0 ~ /^+(\.*)?/) print}' 01#.01 $ Regards, Rmkganesh. (3 Replies)
Discussion started by: rmkganesh
3 Replies

2. Shell Programming and Scripting

Retreiving part of a mail ID

Hi all, I want to retrieve a part of the mail ID. Im using Ksh. The mail ID's i handle are of the type: abc.def@ghi.com I want the abc part alone. Here is the code i used: a=`echo $mailid |sed 's/\(.*\)..../\1/'` echo $a but the output i get is abc.def@ghi I dont know... (2 Replies)
Discussion started by: Jayaraman
2 Replies

3. Shell Programming and Scripting

Adding numbers matching with words

Hi All, I have a file which looks like this: abc 1 abc 2 abc 3 abc 4 abc 5 bcd 1 bcd 3 bcd 3 bcd 5 cde 7 This file is just a miniature version of what I really have. Original file is some 1 million lines long. I have tried to come up with the code for what I wish to accomplish... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Shell Programming and Scripting

Regex/egrep matching numbers in brackets

Experts: I don't know that regular expressions will ever be easy for me, so if one of you guru's could help out, I'd appreciate it. I'm trying to match a line in our syslog, but I can't figure out how to match a number inside a bracket. This is what I'm trying to match. "Jul 16 00:01:34... (2 Replies)
Discussion started by: jdveencamp
2 Replies

5. Shell Programming and Scripting

Matching Numbers in Bash/AWK

Hi, I need to match up some numbers in one file to the closest numbers in other file and produce an output file. File one (f1.txt) is laid out like this PCode Lon Lat AB10 1AA 57.148235 -2.096648 BB2 3JD 53.728563 -2.47852 LU4 9ET... (4 Replies)
Discussion started by: ian_gooch
4 Replies

6. UNIX for Dummies Questions & Answers

Matching numbers of characters in two lines

Dear all, I'm stuck on a certain problem regarding counting the number of characters in one line and then adjusting the number of characters of another line to this number. This was my original input data: @HWI-ST471_57:1:1:1231:2079/2... (4 Replies)
Discussion started by: DerSeb
4 Replies

7. Shell Programming and Scripting

How to find the matching numbers between 2 files Using R language??

Hi friends,, I need ur help very urgently.I have 2 files which have more than 5000 numbers,I want to find the matching numbers between 2 files using R language.I dont know how to use for loop in R.I tried to get a result,,but didnt get, file1 is like 1061909 1162391... (1 Reply)
Discussion started by: sureshraj
1 Replies

8. Shell Programming and Scripting

count numbers of matching rows and replace its value in another file

Hello all, can you help me in this problem, assume We have two txt file (file_1 and file_3) one is file_1 contains the data: a 0 b 1 c 3 a 7 b 4 c 5 b 8 d 6 . . . . and I need to count the lines with the matching data (a,b,..) and print in new file called file_2 such as the... (4 Replies)
Discussion started by: GoldenFalcon10
4 Replies

9. UNIX for Dummies Questions & Answers

Retreiving and storing date...

First of all want to apologize for such a simple question. Very "new" to UNIX and have just taken a small intro class. I need to pull back YYYYMMDD and store it in a field to be used later. I figured out date "+%Y%m%d" returns the date in that format, just not sure how to store it. I am... (7 Replies)
Discussion started by: cards0622
7 Replies

10. Shell Programming and Scripting

matching numbers

hi all I have a 2 files. both the files have some numbers and i want to find out each number in file1 is existing or not in file2. if not then put it into new file. if yes then also in a seperate file i can not use diff command as the files are different and no order has been defined. ... (2 Replies)
Discussion started by: infyanurag
2 Replies
Login or Register to Ask a Question