The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using a vaiable parameters and values to find and tar jjminkle Shell Programming and Scripting 1 05-02-2008 05:12 PM
Copy unique files between two directories in Solaris sujoy101 Shell Programming and Scripting 2 03-22-2008 02:59 AM
grepping many values from same files Sreejith_VK Shell Programming and Scripting 2 03-15-2008 08:41 AM
to retrieve unique values mahalakshmi Shell Programming and Scripting 3 02-05-2007 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-31-2007
sudheshnaiyer sudheshnaiyer is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
Need to find only unique values for a given tag across the files

Need to find only unique values for a given tag across the files:

For eg:

Test1:
<Tag1>aaa</Tag1>
<Tag2>bbb</Tag2>
<Tag3>ccc</Tag3>

Test2:
<Tag1>aaa</Tag1>
<Tag2>ddd</Tag2>
<Tag3>eee</Tag3>

Test3:
<Tag1>aaa</Tag1>
<Tag2>ddd</Tag2>
<Tag3>eee</Tag3>

Test4:
<Tag1>bbb</Tag1>
<Tag2>ddd</Tag2>
<Tag3>eee</Tag3>

grep "<Tag1>" test* --> This command will return the following
test1:<Tag1>aaa</Tag1>
test2:<Tag1>aaa</Tag1>
test3:<Tag1>aaa</Tag1>

But I need the following results:

test1:<Tag1>aaa</Tag1>
test4:<Tag1>bbb</Tag1> ==> I don't want "test2" and "test3" to appear since they are same as "test1" results
  #2 (permalink)  
Old 08-31-2007
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,656
What have you tried so far? Which unix utilities are you using?

Are you posting homework problems?
  #3 (permalink)  
Old 08-31-2007
sudheshnaiyer sudheshnaiyer is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
I have used grep command. This gives me all the occurances. I only need unique occurances.

No, this is not a home work problem

I need to do this in production. I have simplied my production problem using a simple example.
  #4 (permalink)  
Old 09-01-2007
Nagabhushan Nagabhushan is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
hi buddy,

use this
grep "<Tag1>" tag|uniq
  #5 (permalink)  
Old 09-01-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Quote:
hi buddy,

use this
grep "<Tag1>" tag|uniq
Sorry Buddy, wrong approach. Here is the solution,

Code:
grep "<Tag1>" test*|sort -t: -k2 -u
Cheers,
K
  #6 (permalink)  
Old 09-01-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Code:
awk '/<Tag1>/ { arr[$0]++ }END{ for ( i in arr ) { print i } }' test[1-4]
  #7 (permalink)  
Old 09-01-2007
sudheshnaiyer sudheshnaiyer is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
Thank you very much. Both of them work!
Sponsored Links
Closed Thread

Bookmarks

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

BB 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 -4. The time now is 04:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0