awk script issue : comparing two files with a pattern


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Network awk script issue : comparing two files with a pattern

File 1
#################################################################
Code:
pma.zcal.iop_pma_zcal_cntl (2710.080 115.200)
pma.lanea23.rx0.cntl (696.960 844.800)
pma.lanea67.rx0.cntl (1733.760 844.800)
pma.zcal.iop_pma_zcal_cust (2280.960 115.200)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_init_cntl (2327.040 1444.800)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_reg_cntl (2436.480 1411.200)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_clk_cntl (2603.520 1497.600)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_cntl_g3 (2646.720 1404.800)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_cntl_g2 (2373.120 1404.800)
pma.lanea23.rx0.cdr_a (624.960 1040.000)
pma.lanea23.rx0.cdr_b (624.960 1379.200)
pma.lanea67.rx0.cdr_a (1805.760 1040.000)
pma.lanea67.rx0.cdr_b (1805.760 1379.200)
pma.lanea23.rx0.analog_b (207.360 1574.400)
pma.lanea23.rx0.analog_a (207.360 844.800)
pma.lanea67.rx0.analog_b (2223.360 1574.400)
pma.lanea67.rx0.analog_a (2223.360 844.800)
pma.lanea23.tx0.tx_cust0 (967.680 844.800)
pma.lanea23.tx1.tx_cust0 (967.680 1574.400)
pma.lanea67.tx0.tx_cust0 (1451.520 844.800)

File 2
####################################################################
Code:
pma.zcal.iop_pma_zcal_cust (2268.68 115.2)
pma.lanea23.tx0.tx_cntl0.cntl_mac0 (906.44 998.4)
pma.lanea23.tx1.tx_cntl0.cntl_mac0 (906.44 1420.8)
pma.lanea67.tx0.tx_cntl0.cntl_mac0 (1511.24 998.4)
pma.lanea67.tx1.tx_cntl0.cntl_mac0 (1511.24 1420.8)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_clk_cntl (2599.88 1497.6)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_init_cntl (2323.4 1446.4)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_cntl_g3 (2643.08 1404.8)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_cntl_g2 (2369.48 1404.8)
pma.lanea23.rx0.cdr_a (624.2 1040)
pma.lanea23.rx0.cdr_b (624.2 1379.2)
pma.lanea67.rx0.cdr_a (1805 1040)
pma.lanea67.rx0.cdr_b (1805 1379.2)
pma.iop_pma_pll0.iop_pma_pll_cust (2268.68 294.4)
pma.iop_pma_pll0.iop_pma_pll_control.iop_pma_pll_reg_cntl (2432.84 1412.8)
pma.lanea23.rx0.cntl (696.2 844.8)
pma.lanea67.rx0.cntl (1733 844.8)
pma.lanea23.rx0.analog_b (206.6 1574.4)
pma.lanea23.rx0.analog_a (206.6 844.8)
pma.lanea67.rx0.analog_b (2222.6 1574.4)

############################################################################
Need an awk script which can compare field 1 of both the files and according to the match
replace second and third fields of the file 1 with the second and third field of the file2
Second and third fields are Numbers like (2373.120 1404.800)
I tried to write an awk script with a small piece of code , but it is not working
Code:
awk '{ while ((getline  <"file1") > 0 ) file1[$2]=$3 } for (line in final_temp) if (line match($1,line))
{ gsub{$2,$3} )}'1 ptu1

Any help in this regards is highly appreciated
Thanks
Jaita
Moderator's Comments:
Mod Comment
Please use code tags!

Last edited by vgersh99; 11-03-2010 at 11:55 AM.. Reason: Code tags, please!
# 2  
Code:
nawk 'FNR==NR {f2[$1]=$2;f3[$1]=$3;next} $1 in f2 {$2=f2[$1];$3=f3[$1]}1' file2 file1

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #986
Difficulty: Medium
The X Window System is installed by default in FreeBSD.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script issue redirecting to multiple files after matching pattern

Hi All I am having one awk and sed requirement for the below problem. I tried multiple options in my sed or awk and right output is not coming out. Problem Description ############################################################### I am having a big file say file having repeated... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

Comparing two files issue.

more prod.properties # remote connection details cdr_url=http://myprod.col.net:1890/service cdr_user=user1 cdr_pswd=pass11 boot_time=ON more back.properties cdr_url=http://myback.col.net:1890/service cdr_user=user1 cdr_pswd=pass11 storage=file I need to compare the back.properties... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. UNIX for Dummies Questions & Answers

Comparing two files issue

Hi all, I need your help fixing an issue with this code. I am a newbie to UNIX programming and there is an issue with this code I am hoping you can help me correct. I have two files (system_files with 8342 records and rules1.txt file with 762 records). My understanding from the script below, is... (2 Replies)
Discussion started by: Mustafa19804
2 Replies

4. Shell Programming and Scripting

Comparing the two files using awk script

Hi all, Can you please help me to find out that where is the problem in my script or either my way of writing the shell command on the prompt is not right? Actually, I want to compare the second column "$1" of the file "t1" with all the columns of second file "t2", if there is a match then the... (2 Replies)
Discussion started by: coder83
2 Replies

5. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

6. Shell Programming and Scripting

comparing 2 files with awk

Hi, I'm a new user in awk and i'm trying to compare two files to create a third one if some values match in both files. The first file has this content: s 45.960746365 _21_ AGT 2490 [21:0 22:0 s 45.980418496 _21_ AGT 2491 [21:0 22:0 s 46.000090627 _21_ AGT 2492 [21:0 22:0 s 47.906552206... (2 Replies)
Discussion started by: carlosoria
2 Replies

7. Shell Programming and Scripting

Awk script / comparing two files

Goal: To combine the data from two files into one file. File1 = 11 fields, the first field is the unique key File2 = 2 fields, the first field is the unique key What I want to do is match File2:column1 with File1:column1 and if it matches, to add the data from File2:column2 to the matching... (2 Replies)
Discussion started by: jmcgranahan
2 Replies

8. Shell Programming and Scripting

Issue in comparing (cmp) two files

Hi All, I have to compare set of files so I created a case statement with the option to give more than one file to compare. The Problem now i am facing is, if I compare the files directly, from prompt or just using the script only for a particular file then It's saying No difference, but If I... (4 Replies)
Discussion started by: Sudhar
4 Replies

9. Shell Programming and Scripting

Indexing or Filtering code- Pattern Search by comparing two files

So here is goes to the Gurus of shell programming......I have tried a lot of different ways and its a very challenging code to write but i am enjoying it as i troubleshoot and hopefully someone can provide me a better option....Thank you in advance for your time and support....Much appreciated... ... (12 Replies)
Discussion started by: aavam
12 Replies

10. Shell Programming and Scripting

comparing two files using awk.

Hi All, a new bie to awk, How to compare substring of col1,file 1 with col2file2 and get file1contents+col3file2 as output. file1 ----- kumarfghh,23,12000,5000 rajakumar,24,14000,2500 rajeshchauhan,25,16000,2600 manoj,26,17000,2300 file 2 -------- 123,kumar,US, 123,sukumar,UK... (4 Replies)
Discussion started by: jerome Sukumar
4 Replies

Featured Tech Videos