If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > URGENT : Compare field in two files for mixed O/P

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-09, 11:01
hunter85 hunter85 is offline
Registered User
 
Join Date: Jun 2009
Posts: 3
URGENT : Compare field in two files for mixed O/P

Hi Experts,

I have a problem. Can you Help me?

I need a UNIX shell script for the below logic using AWK. The logic must lay on by vaildating the first field.I am using -KSH.

I am in real hurry. : Your help will be highly appreciated.

Table 1:

Cricket 16 28
Tennis 26 15
Wrestling 12 34

Table 2:
Cricket 25 26
***** 16 13
Wrestling 11 22

I need output as in table3.


Table 3:

Cricket 16 28 25 26
***** NA NA 16 13
Tennis 26 15 NA NA
Wrestling 12 34 11 22

If any questions plz ask me. Thankyou for your consideration.
Reply With Quote
  #2 (permalink)  
Old 06-03-09, 11:32
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Looks easy enough - can you explain why it's urgent? why it needs to be in awk? or is it just late homework you'd rather we did for you?
Reply With Quote
  #3 (permalink)  
Old 06-03-09, 11:48
hunter85 hunter85 is offline
Registered User
 
Join Date: Jun 2009
Posts: 3
I have to findout the logic and I am learning "AWK" too.

Teach/suggest me if you can. Thanks for your consideration.
Reply With Quote
  #4 (permalink)  
Old 06-03-09, 12:28
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
This site's not bad.

Read in data from files, assign values to arrays, print values out in required format, stop.
Reply With Quote
  #5 (permalink)  
Old 06-04-09, 03:16
hunter85 hunter85 is offline
Registered User
 
Join Date: Jun 2009
Posts: 3
Angry

Hi...

I already know how to print this format. But my concern is that the program should validate the first field (As I specified earlier), then it must the print the O/P in required format.

Could you plz give me ur valuable inputs?
Reply With Quote
  #6 (permalink)  
Old 06-04-09, 04:19
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Quote:
Originally Posted by hunter85
I already know how to print this format. But my concern is that the program should validate the first field (As I specified earlier), then it must the print the O/P in required format.
Validate it in what fashion, that it's spelt correctly? that it begins with a capital letter? that it's followed by 2 numbers?
Quote:
Originally Posted by hunter85
Could you plz give me ur valuable inputs?
I'd suggest you go along to classes, do any background reading and then do your own homework. If you can't be bothered to put any effort into it then why on earth should we?
Reply With Quote
  #7 (permalink)  
Old 06-05-09, 15:55
rana4bhu rana4bhu is offline
Registered User
 
Join Date: Jun 2009
Posts: 2
Thumbs down comparing two files...

@HUNTER

awk ' FILENAME==ARGV[1] { a[$1]=$2" "$3 }
FILENAME==ARGV[2] { if(a[$1]=="") {a[$1]="NA NA "$2" "$3 } else { a[$1]=a[$1]" "$2" "$3 } }
END { for(i in a) print i" "a[i]}' f1 f2 | sort |
awk '{ if(NF<4) { print $0" NA NA"} else { print $0 }}'


it will solve ur problem....
Reply With Quote
  #8 (permalink)  
Old 06-05-09, 15:57
rana4bhu rana4bhu is offline
Registered User
 
Join Date: Jun 2009
Posts: 2
Thumbs down

Quote:
Originally Posted by hunter85
Hi Experts,

I have a problem. Can you Help me?

I need a UNIX shell script for the below logic using AWK. The logic must lay on by vaildating the first field.I am using -KSH.

I am in real hurry. : Your help will be highly appreciated.

Table 1:

Cricket 16 28
Tennis 26 15
Wrestling 12 34

Table 2:
Cricket 25 26
***** 16 13
Wrestling 11 22

I need output as in table3.


Table 3:

Cricket 16 28 25 26
***** NA NA 16 13
Tennis 26 15 NA NA
Wrestling 12 34 11 22

If any questions plz ask me. Thankyou for your consideration.


awk ' FILENAME==ARGV[1] { a[$1]=$2" "$3 }
FILENAME==ARGV[2] { if(a[$1]=="") {a[$1]="NA NA "$2" "$3 } else { a[$1]=a[$1]" "$2" "$3 } }
END { for(i in a) print i" "a[i]}' Table11 Table2 | sort |
awk '{ if(NF<4) { print $0" NA NA"} else { print $0 }}' > Table3


now Table3 will contain .... wt u want.......

Cricket 16 28 25 26
***** NA NA 16 13
Tennis 26 15 NA NA
Wrestling 12 34 11 22

Enjoyyyyyyyyyyyyyyyyyyy
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On