UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 6th, 2006, 09:27 AM
nevil_m nevil_m is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 68 nevil_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 49 m 24 sec
Reputation Power: 3
Diff command

Hi,

I am having two files. Data in both the files are as
File 1 :

BCSU-1 0032 WO-EX -
BCSU-2 0034 SP-EX -
BCSU-3 0045 WO-EX -
BCSU-4 0046 WO-EX -

File 2:

BCSU-1 0032 SP-EX -
BCSU-3 0045 WO-EX -

I need a command which will compare these two files and give me an output as,

BCSU-2 0034 SP-EX -
BCSU-4 0046 WO-EX -

In short, the output file should not contain those lines where common first word exists. I tried using diff command, but it compares the whole line instead of comparing only the first word. Please let me know how to tackle this problem.

BR
Nevil

Reply With Quote
  #2  
Old March 6th, 2006, 01:46 PM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
Not sure what kind of shell you're using. With bash or ksh, this works fine:
Code:
for i in `awk '{print $1}' file1`
do
  if ! grep $i file2 >/dev/null 2>&1
  then
    grep $i file1
  fi

  if ! grep $i file1 >/dev/null 2>&1
  then
    grep $i file2
  fi
done
Don't know of any single command that will do what you want.

If either file has more than one line that starts with "BCSU-2" (as an example) then this hack might not work properly.

Reply With Quote
  #3  
Old March 12th, 2006, 01:54 AM
nevil_m nevil_m is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 68 nevil_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 49 m 24 sec
Reputation Power: 3
Its worked for me. Thanks a ton.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Diff command


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT