How to replace match data in 2 file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace match data in 2 file.
# 1  
Old 09-19-2010
How to replace match data in 2 file.

How to replace match data in 2 file. to new file


My log.txt (100,000 line)
Code:
11415304503฿90255050001฿3฿23/02/2009 13:12:38฿17/04/2009 13:04:59฿27/03/2009 4:13:54
11494069063฿90259730001฿3฿27/10/2008 13:14:21฿02/11/2009 14:34:01฿09/10/2009 4:13:26
11497298316฿90825970008฿5฿29/03/2009 20:23:08฿30/03/2009 11:27:48฿null
11415642496฿90825970008฿5฿29/03/2009 21:12:51฿10/10/2009 21:12:51฿11/09/2009 2:44:39
11475600066฿90825320003฿2฿30/03/2009 0:18:09฿29/09/2010 2:37:58฿null
11404525129฿90259160001฿5฿29/03/2009 19:59:32฿20/11/2010 2:49:26฿null
.
.
.
.
11497387955฿90259160001฿5฿29/03/2009 20:42:10฿23/05/2010 20:42:10฿null
11477841845฿90259730001฿5฿26/03/2009 23:24:38฿10/06/2009 4:50:47฿15/04/2009 4:53:39
11414026192฿90825970008฿2฿29/03/2009 19:28:59฿14/10/2010 3:46:05฿14/09/2010 3:46:05

My match data.log (300 line)
Code:
1925505    90255050001
1925988    90259880003
1925989    90259730001
1925989    90259730001
1925989    90259730002
.
.
.
.
1982590    90825900005
1982590    90825970008

I want out put newmatch_log (100,000 line)
Code:
11415304503฿1925505฿90255050001฿3฿23/02/2009 13:12:38฿17/04/2009 13:04:59฿27/03/2009 4:13:54
11494069063฿1925989฿90259730001฿3฿27/10/2008 13:14:21฿02/11/2009 14:34:01฿09/10/2009 4:13:26
.
.
.
.
11414026192฿1982590฿90825970008฿2฿29/03/2009 19:28:59฿14/10/2010 3:46:05฿14/09/2010 3:46:05

Thanks for any help guys, I am new to this and feel lost.
# 2  
Old 09-19-2010
This should do the job (strange separator)
Code:
#!/bin/bash
IFS='฿'
while read A B C
do
   D=$(grep -m1 $B 'My match data.log' | cut -d' ' -f1)
   echo "${A}฿${D}฿$B฿$C"
done < 'My log.txt'

This User Gave Thanks to frans For This Post:
# 3  
Old 09-19-2010
Code:
awk '
NR==FNR{a[$2]=$1;next}
{
   split($0,b,"฿")
   if (b[2] in a) sub(b[2],a[b[2]]"."b[2])
}1' date.log log.txt

This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 09-19-2010
Code:
#!/usr/bin/env ruby  
h={};h.default=""
File.readlines("file").each{|v| g=v.split;h[g[1]]=g[0] }
File.open("file1").each do |line|
    sp=line.split("฿")
    h.has_key?(sp[1]) and sp[1]=h[sp[1]]+"฿"+sp[1]
    print "#{sp.join("฿")}"
end

This User Gave Thanks to kurumi For This Post:
# 5  
Old 09-20-2010
It's work

Last edited by ooilinlove; 09-20-2010 at 01:17 AM..
# 6  
Old 09-20-2010
which one or all of them?
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

Help search and replace the last occurance of match in a file

Hi I want to replace only the last occurance of "union all" in input file with ";" I tried with sed 's/union all/;/g' in my input file, it replaced in all lines of input file Eg: select column1,column2 from test1 group by 2 union all select column1,column2 from test2 group by 2 union all ... (9 Replies)
Discussion started by: antosr7
9 Replies

3. Shell Programming and Scripting

sed : replace Nth match in a file

I have a situation where a file "config.txt" looks like this Servername: OS: Serername: OS: Servername: OS: .... .... ... Servername: OS: looking for the sed syntax to replace the "Nth" occurrence of Servername (i would apply the same logic to OS as well), want to replace the Nth... (4 Replies)
Discussion started by: alldbest
4 Replies

4. Shell Programming and Scripting

Replace value in csv file with match from another file

Good morning everyone and hello unix.com! I'm trying to solve a problem and was unable to find a solution after a forum research. So hopefully you can help me get this solved. I have these two csv files: file1.csv ID,REFERENCE,STATUS 1,2,0 2,4,1 3,1,0 file2.csv... (2 Replies)
Discussion started by: RKos
2 Replies

5. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

6. Shell Programming and Scripting

Match same file column data

File A B07 U51C 4434 L662C 4412 B07 L64U 612 L651B 4434 B07 L11C 4434 R151B 4434 B05 L12Z 612 L51B 4434 B01 651Z 612 L651C 4434 B04 A51Z 612 L51A 4434 L07 B08D 4434 B1B 4434 B07 RU8D 4434 L51A 4434 B07 L58D 4434 B51C 4434 B07 LA8D 4434 L4B 4434 Now i want File B Output B07... (2 Replies)
Discussion started by: asavaliya
2 Replies

7. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

8. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies

9. 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

10. Shell Programming and Scripting

search and replace the last occurance of a match in a file

HI please let me know if there is any command to search and replace only the last occurence of a string in aline. Eg: " This cat is a cat with a tail longer of all cat." I need to replace only the last "cat" in the above line. thanks (3 Replies)
Discussion started by: harikris614
3 Replies
Login or Register to Ask a Question