Combining two files with a reference coloumn | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Combining two files with a reference coloumn

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
sau_boy sau_boy is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 25 January 2013, 4:35 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Combining two files with a reference coloumn

Hi all,

this is file1.txt

Code:
10.210.226.21 alarmSupervisionActive=true 
10.64.136.209 alarmSupervisionActive=true 
10.64.174.209 alarmSupervisionActive=true 
10.64.182.65 alarmSupervisionActive=true 
10.66.193.113 alarmSupervisionActive=true 
10.80.124.67 alarmSupervisionActive=true 
10.80.124.68 alarmSupervisionActive=true 
10.80.124.69 alarmSupervisionActive=true 
10.80.124.70 alarmSupervisionActive=true 
10.80.124.71 alarmSupervisionActive=true 
10.80.124.72 alarmSupervisionActive=true 
10.80.124.73 alarmSupervisionActive=true

and this is file2.txt

Code:
10.210.226.21 STN_systemClockUDP_Port=123;
10.64.136.209 STN_systemClockUDP_Port=123;
10.64.174.209 STN_systemClockUDP_Port=123;
10.64.182.65 STN_systemClockUDP_Port=123;
10.66.193.113 STN_systemClockUDP_Port=123;
10.80.124.67 STN_systemClockUDP_Port=123;
10.80.124.68 STN_systemClockUDP_Port=123;
10.80.124.69 STN_systemClockUDP_Port=123;
10.80.124.70 STN_systemClockUDP_Port=123;
10.80.124.71 STN_systemClockUDP_Port=123;
10.80.124.72 STN_systemClockUDP_Port=123;
10.80.124.73 STN_systemClockUDP_Port=123;

expecting the output.txt like below;

Code:
10.210.226.21 STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.64.136.209 STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.64.174.209 STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.64.182.65  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.66.193.113 STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.67  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.68  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.69  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.70  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.71  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.72  STN_systemClockUDP_Port=123; alarmSupervisionActive=true
10.80.124.73  STN_systemClockUDP_Port=123; alarmSupervisionActive=true

I try join a1 a2 but doesnt work! Waiting for helps? Thanks so much
Sponsored Links
    #2  
Old 01-25-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 October 2014, 2:21 PM EDT
Location: San Jose, CA, USA
Posts: 4,881
Thanks: 182
Thanked 1,641 Times in 1,392 Posts
In what way does join not work?

What error message does it produce?

What does it write to standard output?
Sponsored Links
    #3  
Old 01-25-2013
tukuyomi tukuyomi is online now
Registered User
 
Join Date: Aug 2009
Last Activity: 21 October 2014, 2:09 PM EDT
Location: France
Posts: 318
Thanks: 19
Thanked 81 Times in 76 Posts

Code:
unix.com$ awk 'NR==FNR{A[$1]=$2;next}$0=$0" "A[$1]' file1 file2

    #4  
Old 01-25-2013
sau_boy sau_boy is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 25 January 2013, 4:35 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The output.txt appears like below, no errors actually, I want coloumn by coloumn..


Code:
10.210.226.21 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.64.136.209 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.64.174.209 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.64.182.65 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.66.193.113 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.67 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.68 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.69 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.70 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.71 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.72 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

10.80.124.73 alarmSupervisionActive=true 
 STN_systemClockUDP_Port=123;

---------- Post updated at 03:03 PM ---------- Previous update was at 02:58 PM ----------


Code:
omerkah@unix> awk 'NR==FNR{A[$1]=$2;next}$0=$0" "A[$1]' a1 a2
awk: syntax error near line 1
awk: bailing out near line 1

when I try
Code:
awk 'NR==FNR{A[$1]=$2;next}$0=$0" "A[$1]' a1 a2

errors appears, unfortunately. Thanks for the reply
Sponsored Links
    #5  
Old 01-25-2013
tukuyomi tukuyomi is online now
Registered User
 
Join Date: Aug 2009
Last Activity: 21 October 2014, 2:09 PM EDT
Location: France
Posts: 318
Thanks: 19
Thanked 81 Times in 76 Posts
Which system are you on?
Sponsored Links
    #6  
Old 01-25-2013
sau_boy sau_boy is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 25 January 2013, 4:35 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The system is;


Code:
omerkah@unix> uname -a
SunOS claps8 5.10 Generic_147440-07 sun4u sparc SUNW,SPARC-Enterprise

Sponsored Links
    #7  
Old 01-25-2013
tukuyomi tukuyomi is online now
Registered User
 
Join Date: Aug 2009
Last Activity: 21 October 2014, 2:09 PM EDT
Location: France
Posts: 318
Thanks: 19
Thanked 81 Times in 76 Posts
An internet search mentioned to try using nawk then...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help in reading N days files from a Directory & combining the files dsfreddie UNIX for Dummies Questions & Answers 1 12-30-2011 11:33 AM
combining two files rock1 UNIX for Dummies Questions & Answers 36 09-29-2008 02:10 PM
Combining two files hemangjani Shell Programming and Scripting 7 06-13-2007 10:32 PM
Combining files Enda Martin UNIX for Dummies Questions & Answers 2 07-20-2001 10:31 AM
combining files apalex UNIX for Dummies Questions & Answers 3 06-19-2001 09:49 AM



All times are GMT -4. The time now is 02:21 PM.