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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need to find only unique values for a given tag across the files
# 1  
Old 08-31-2007
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  
Old 09-01-2007
What have you tried so far? Which unix utilities are you using?

Are you posting homework problems?
# 3  
Old 09-01-2007
I have used grep command. This gives me all the occurances. I only need unique occurances.

No, this is not a home work problem Smilie

I need to do this in production. I have simplied my production problem using a simple example.
# 4  
Old 09-01-2007
hi buddy,

use this
grep "<Tag1>" tag|uniq
# 5  
Old 09-01-2007
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
kamitsin
# 6  
Old 09-01-2007
Code:
awk '/<Tag1>/ { arr[$0]++ }END{ for ( i in arr ) { print i } }' test[1-4]

# 7  
Old 09-01-2007
Thank you very much. Both of them work!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. UNIX for Beginners Questions & Answers

Merge 4 bim files by keeping only the overlapping variants (unique rs values )

Dear community, I am facing a problem and I kindly ask your help: I have 4 different data sets consisted from 3 different types of array. On each file, column 1 is chromosome position, column 2 is SNP id etc... Lets say I have the following (bim) datasets: x2014: 1 rs3094315... (4 Replies)
Discussion started by: fondan
4 Replies

3. UNIX for Beginners Questions & Answers

Find unique values but only in column 1

Hi All, Does anyone have any suggestions/examples of how i could show only lines where the first field is not duplicated. If the first field is listed more than once it shouldnt be shown even if the other columns make it unique. Example file : 876,RIBDA,EC2 876,RIBDH,EX7 877,RIBDF,E28... (4 Replies)
Discussion started by: mutley2202
4 Replies

4. Shell Programming and Scripting

How to merge two files with unique values matching.?

I have one script as below: #!/bin/ksh Outputfile1="/home/OutputFile1.xls" Outputfile2="/home/OutputFile2.xls" InputFile1="/home/InputFile1.sql" InputFile2="/home/InputFile2.sql" echo "Select hobby, class, subject, sports, rollNumber from Student_Table" >> InputFile1 echo "Select rollNumber... (3 Replies)
Discussion started by: Sharma331
3 Replies

5. Shell Programming and Scripting

Count Unique values from multiple lists of files

Looking for a little help here. I have 1000's of text files within a multiple folders. YYYY/ /MM /1000's Files Eg. 2014/01/1000 files 2014/02/1237 files 2014/03/1400 files There are folders for each year and each month, and within each monthly folder there are... (4 Replies)
Discussion started by: whegra
4 Replies

6. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

7. Shell Programming and Scripting

Find out values between xml tag

Find out values between xml tag ....... ABC><name></ABC><xyz>test</xyz>..here some other tag... <ABC><NUMBER></ABC><xyz>12345</xyz>.... ....... I want to take between bewtween ABC><NUMBER></ABC><xyz> to </xyz> that is 12345 (3 Replies)
Discussion started by: Jairaj
3 Replies

8. UNIX for Dummies Questions & Answers

Grep to find matching patern and return unique values

Request: grep to find given matching patern and return unique values, eliminate the duplicate values I have to retrieve the unique folder on the below file contents like; /app/oracle/build_lib/pkg320.0_20120927 /app/oracle/build_lib/pkg320.0_20121004_prof... (5 Replies)
Discussion started by: Siva SQL
5 Replies

9. Shell Programming and Scripting

Find and count unique date values in a file based on position

Hello, I need some sort of way to extract every date contained in a file, and count how many of those dates there are. Here are the specifics: The date format I'm looking for is mm/dd/yyyy I only need to look after line 45 in the file (that's where the data begins) The columns of... (2 Replies)
Discussion started by: ronan1219
2 Replies

10. Shell Programming and Scripting

comparing 2 text files to get unique values??

Hi all, I have got a problem while comparing 2 text files and the result should contains the unique values(Non repeatable). For eg: file1.txt 1 2 3 4 file2.txt 2 3 So after comaping the above 2 files I should get only 1 and 4 as the output. Pls help me out. (7 Replies)
Discussion started by: smarty86
7 Replies
Login or Register to Ask a Question