Grep distinct


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep distinct
# 1  
Old 11-02-2011
Grep distinct

Hello,

I have a file which looks like:
Code:
%_SPE_RDP_NUM_ECH(7)*************%
%_SPE_RDP_NUM_ECH(70)************%
%_SPE_RDP_NUM_ECH(71)************%
%_SPE_RDP_NUM_ECH(72)************%
%_SPE_RDP_NUM_ECH(8)*************%
%_SPE_RDP_NUM_ECH(9)*************%
%_SPE_FLUXPREV_PRES1_MT_HT(2)****%
%_SPE_FLUXPREV_PRES1_MT_HT(20)***%
%_SPE_FLUXPREV_PRES1_MT_HT(21)***%
%_SPE_FLUXPREV_PRES1_MT_HT(22)***%
%_SPE_FLUXPREV_PRES1_MT_HT(23)***%
%_SPE_FLUXPREV_PRES1_MT_HT(24)***%
%_SPE_FLUXPREV_PRES1_MT_HT(25)***%

and so I just want to obtain SPE_RDP_NUM_ECH once and SPE_FLUXPREV_PRES1_MT_HT once.
In fact, I have more key words like these 2, what I mean is I want just one occurrence of each one despite de number between parenthesis.
Can someone help me do this?
Thks a lot!

Last edited by radoulov; 11-02-2011 at 06:57 PM.. Reason: Code tags!
# 2  
Old 11-02-2011
You can start with:
Code:
awk -F"(" '{a[$1]=1}END{for (i in a) print i}' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 11-02-2011
Code:
nawk -F'(' '!a[$1]++' myFile

# 4  
Old 11-02-2011
Thanks bartus11!
Just to understand better what I'm doing, what does the part

a[$1]=1

mean?
# 5  
Old 11-02-2011
It is creating associative array containing your required string as its keys and "1"s as values.
# 6  
Old 11-03-2011
Thank you very much!
I understand the idea.

I changed it to
Code:
a[$1]<=2

and I got 2 ocurrences instead of 1.

Last edited by vbe; 11-03-2011 at 12:35 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get distinct value in bash between two string

Sorry for my english i am french So i am receiving from a script this prompt : tabular;critical;mirroring;DG INTlocaldg VOLUME appears tabular;critical;mirroring;DG INTlocaldg VOLUME bh3vm tabular;critical;mirroring;DG INTlocaldg VOLUME dev tabular;critical;mirroring;DG INTlocaldg VOLUME... (3 Replies)
Discussion started by: cterra
3 Replies

2. Shell Programming and Scripting

Need the distinct of these lines

Red Hat Enterprise Linux 5.4 I have a text file (error log file) , which has occurences of an error message like ORA-01652: unable to extend temp segment by 8 in tablespace xxxxxThere are around 3000 error messages like this in the error log file. But there are only 7 or 8 distinct... (3 Replies)
Discussion started by: John K
3 Replies

3. Shell Programming and Scripting

Get the distinct of a particular field

From the below ps output , I want the distinct values of the third field (ie. I need the distinct PPIDs) $ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 Nov 10 - 48:49 /etc/init root 1769576 1 0 Nov 10 - 0:07... (1 Reply)
Discussion started by: polavan
1 Replies

4. Shell Programming and Scripting

Search distinct files

Hello , Can anyone help me with my below query I am trying to find a text in directory of files via below command grep -i cmps_cgs_crs_rfnc_id * But it returns multiple times same file name i.e if the text found in a file 4 times the file name shown 4 times in the o/p Is... (1 Reply)
Discussion started by: Pratik4891
1 Replies

5. Web Development

SQL - Distinct plus more

Hi all, I have an interesting and I am sure simple question for yau'll. Basically this is what I am after: The table: CREATE TABLE places (id INT, city VARCHAR(24), name VARCHAR(24)); The data: id = 1, city = canberra, name = aaron id = 2, city = canberra, name = andrew id = 3, city... (4 Replies)
Discussion started by: STOIE
4 Replies

6. Shell Programming and Scripting

distinct values of all the fields

I am a beginner to scripting, please help me in this regard. How do I create a script that provides a count of distinct values of all the fields in the pipe delimited file ? I have 20 different files with multiple columns in each file. I needed to write a generic script where I give the number... (2 Replies)
Discussion started by: vukkusila
2 Replies

7. UNIX for Dummies Questions & Answers

distinct values of all the fields

I am a beginner to scripting, please help me in this regard. How do I create a script that provides a count of distinct values of all the fields in the pipe delimited file ? I have 20 different files with multiple columns in each file. I needed to write a generic script where I give the number... (1 Reply)
Discussion started by: vukkusila
1 Replies

8. Shell Programming and Scripting

grep distinct values

this is a little more complex than that. I have a text file and I need to find all the distinct words that appear in a line after the word TABLESPACE when I grep for just the word tablespace, I get: how do i parse this a little better so i have a smaller file to read? This is just an... (4 Replies)
Discussion started by: guessingo
4 Replies

9. UNIX for Dummies Questions & Answers

Distinct search usisng GREP cmd

Hi All, I have the following problem where I have been trying but not able to resolve it:- I have a file which has some thousands entries. For eg:- The content of the file is :- ============================================== ./admin.cpp:9:#include "framework/RegistryContext.h"... (2 Replies)
Discussion started by: shubhranshu
2 Replies

10. UNIX for Dummies Questions & Answers

how to pick distinct records..........

How can i pick distinct records which consists of duplicate data from a ASCII file using UNIX commands (3 Replies)
Discussion started by: ss4u
3 Replies
Login or Register to Ask a Question