The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare 2 files.. amon Shell Programming and Scripting 8 1 Week Ago 07:34 AM
compare two files charandevu Shell Programming and Scripting 7 03-30-2008 12:20 PM
compare two txt files space13 Shell Programming and Scripting 8 09-22-2006 06:40 AM
compare files and beyond MizzGail UNIX for Dummies Questions & Answers 2 04-25-2003 10:34 AM
compare files ingunix UNIX for Dummies Questions & Answers 3 05-24-2001 08:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-2007
Registered User
 

Join Date: Mar 2007
Location: Manila
Posts: 25
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Compare files

Hi Masters! I know this problem is quite difficult.
I have two files that looked like this:

File1
mary a b d
anne d e
jane g h
sam a


File2
role1 a d c d
role2 e f g h
role3 a b d
role4 a d e
role5 g h


It will first look into file1 then compare to all entries in file2 regardless of arrangement.

The output should be:
mary role1 role3
anne role 4
jane role2 role5
sam role1 role3 role4


I've tried some other way to do this but unsuccessful. Can it be done in UNIX? Please help. Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-10-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,332
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
This looks a lot like homework, so I will not give an answer.

Post what you have tried already and maybe someone will point out where you are going wrong.
Reply With Quote
  #3 (permalink)  
Old 03-10-2007
Registered User
 

Join Date: Mar 2007
Location: Manila
Posts: 25
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
It's not a homework. Actually I tried using excel to manipulate the files but I'm not familiar with macros so I hope someone can help me do it in UNIX.

This will be a repeated process for me and having a right code will really help me a lot. Unfortunately my limited knowledge in UNIX wont help me too.
Reply With Quote
  #4 (permalink)  
Old 03-10-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 396
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by kharen11
Hi Masters! I know this problem is quite difficult.
I have two files that looked like this:

File1
mary a b d
anne d e
jane g h
sam a


File2
role1 a d c d
role2 e f g h
role3 a b d
role4 a d e
role5 g h


It will first look into file1 then compare to all entries in file2 regardless of arrangement.

The output should be:
mary role1 role3
anne role 4
jane role2 role5
sam role1 role3 role4


I've tried some other way to do this but unsuccessful. Can it be done in UNIX?

What are the criteria? This script looks for all lines in File2 that contain any of the letters after the name, but the ouput doesn't match yours:

Code:
while read name a b c d e
do
  [ -n "$a$b$c$d$e" ] &&
  result=$( grep ${a:+-e " $a"} ${b:+-e " $b"} ${c:+-e " $c"} \
             ${d:+-e " $d"} ${e:+-e " $e"} File2 | cut -d ' ' -f1)
  set -- $result
  echo "$name" $result
done < File1
Reply With Quote
  #5 (permalink)  
Old 03-10-2007
Registered User
 

Join Date: Mar 2007
Location: Manila
Posts: 25
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
The files on file1 can go over several rows and columns as well as for file2. For example, mary has a, b and d. It will then search the file2 that contains a, b and d (it should be all not any) which in this case role1 and role3. Then it will begin searching for second entry in file1 who is anne, and so on.
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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



All times are GMT -7. The time now is 09:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102