Find out the match data content?!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find out the match data content?!
# 1  
Old 11-04-2009
Find out the match data content?!

Hi,

Long list of Input file1 content:
1285_t
4860_i
4817_v
8288_c
9626_a
.
.
.

Long list of Input file2 content:
1285_t chris germany
8288_c steve england
9626_a dave swiss
9260_s stephanie denmark
.
.
.

Output file:
1285_t chris germany
8288_c steve england
9626_a dave swiss
.
.
.

How I can extract the Input file2 content that got match with Input file1 data?
Thanks a lot for advise Smilie
# 2  
Old 11-04-2009
Code:
$ grep -f file1 file2
1285_t chris germany
8288_c steve england
9626_a dave swiss

# 3  
Old 11-04-2009
Hi, do you got any idea if I deal with long list of data ?
For short list of data, I believe "grep" is able to handle it.
But for long list of data, it might be difficult Smilie
thanks for your advice ^^
# 4  
Old 11-04-2009
With -m, can save the search time.

-m NUM, --max-count=NUM
Stop reading a file after NUM matching lines. If the input is standard input from a regular
file, and NUM matching lines are output, grep ensures that the standard input is positioned to
just after the last matching line before exiting, regardless of the presence of trailing
context lines. This enables a calling process to resume a search. When grep stops after NUM
matching lines, it outputs any trailing context lines. When the -c or --count option is also
used, grep does not output a count greater than NUM. When the -v or --invert-match option is
also used, grep stops after outputting NUM non-matching lines.

Code:
grep -m 1 -f file1 file2

# 5  
Old 11-04-2009
what about join
Code:
join file1 file2

# 6  
Old 11-04-2009
Hi, I just try the code that you suggested.
Sad to said that it is not worked Smilie
Do you have better suggestion?
Both of my input file 1 and file 2 got different line number.
I just want to print out those content that file 1 and file 2 match at first column.
Really thanks for your help Smilie

---------- Post updated at 04:01 AM ---------- Previous update was at 03:57 AM ----------

thanks a lot.
Even though take some time to do for huge data Smilie
It is worked Smilie
# 7  
Old 11-04-2009
apologize, you have to specify the output file like
Code:
join file1 file2 > file3

I've tried with your sample data and it outputs
1285_t chris germany
8288_c steve england
9626_a dave swiss
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

awk command to get file content until 2 occurrence of pattern match

AWK command to get file content until 3 occurrence of pattern match, INPUT FILE: JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2"> <person>Romi</person> <appName>SAP</appName> </custOptIn> ... (4 Replies)
Discussion started by: prince1987
4 Replies

3. Shell Programming and Scripting

Sorting content between match pattern and move on with awk and sed

S 0.0 0.0 (reg, inst050) k e f d c S 0.0 0.0 (mux, m030) k g r s x v S 0.0 0.0 (reg, inst020) q s n m (12 Replies)
Discussion started by: ctphua
12 Replies

4. Shell Programming and Scripting

Program to match the id and replace one letter in the content

Hi all, I have one file with a sequence and the other file which says the position and the letter to be changed. I have to match two files and replace content. Example is shown which will describe what I want to do. For example, file 1 has many sequences and few are shown below sequence file:... (6 Replies)
Discussion started by: kaav06
6 Replies

5. Shell Programming and Scripting

Column content match and add suffix

My input chr3 galGal3_xenoRefFlat CDS 4178235 4178264 0.000000 + 0 gene_id "T6J4.19; T6J4_19"; transcript_id "T6J4.19; T6J4_19"; chr3 galGal3_xenoRefFlat exon 4178235 4178264 0.000000 + . gene_id "T6J4.19; T6J4_19"; transcript_id "T6J4.19;... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. Shell Programming and Scripting

Extract all content that match exactly only specific word

Input: 21 templeta parent 35718 36554 . - . ID=parent_cluster_50.21.11; Name=Partial%20parent%20for%20training%20set; 21 templeta kids 35718 36554 . - . ID=_52; Parent=parent_cluster_5085.21.11; 21 templeta ... (7 Replies)
Discussion started by: patrick87
7 Replies

7. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

8. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

9. Shell Programming and Scripting

How to find first match and last match in a file

Hi All, I have a below file: ================== 02:53 pravin-root 02:53 pravin-root 03:05 pravin-root 02:55 pravin1-root 02:59 pravin1-root ================== How do I find the first and last value of column 1. For example, how do I find 02:53 is the first time stamp and 03:05 is... (3 Replies)
Discussion started by: praving5
3 Replies

10. UNIX for Dummies Questions & Answers

X11 auth data does not match fake data

We have different unix servers, let say I have server 1 and server 2. Well whenever I ssh from server 1 to server 2, I'm ok, but when I ssh from server 2 to server 1, I can connect just fine, but I get this message: X11 auth data does not match fake data X11 auth data does not match fake data... (1 Reply)
Discussion started by: samytrix
1 Replies
Login or Register to Ask a Question