Distinct search usisng GREP cmd


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Distinct search usisng GREP cmd
# 1  
Old 11-14-2008
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"
./admin.cpp:10:#include "framework/LoggingContext.h"
./adminbatchbase.h:10:#include"framework/RegistryInterface.h"
./adminbatchbase.h:11:#include"framework/LoggingInterface.h"
./adminbatchbase.h:12:#include"framework/BatchException.h"

===============================================

Now if I count the number of occurences of "framework" then it comes to 5(wc -l)
But I want the count to be 2 as there are only 2 distinct files where framework is there.

Could somebdy help me with this?

Thanks,
SD.
# 2  
Old 11-14-2008
Sorry....The below code will not work as per the requirement Smilie

Try using -w option with grep. If you want the search to be extended in multiple files, try the following command

find . 2>/dev/null | xargs grep -w "string" 2>/dev/null

Last edited by sriharsha_kvr; 11-14-2008 at 05:27 AM.. Reason: Requirement wrongly understood
# 3  
Old 11-14-2008
This should work

find . 2>/dev/null | xargs grep -w framework | cut -d ":" -f1 | uniq -d
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Cmd="grep 'Name:' |awk -F' ' '{print $2}'"

Hi Is it possible to get the below code working.? cmd="grep 'Name:' |awk -F' ' '{print $2}'|xargs -i basename {}" echo $cmd ( rman target / <<EOF1 LIST COPY ; exit EOF1 ) | `$cmd` in nutshell I want to be able to preset cmd as depending on script flow it can be... (2 Replies)
Discussion started by: zam
2 Replies

3. Shell Programming and Scripting

To search distinct special char in file

hi, i need to search distinct special character from a file which is a pipe delimited from a specific column for eg: input file.txt aa|bb|cc|$abc aa|bb|ccc|#abol bb|xss|ddd|$xyz nn|yyy|qqq|=qqqq abe|qqq|yyy|=aaa aaa|yyy|zzzz|#aaaa . . . my desired output $ (10 Replies)
Discussion started by: rohit_shinez
10 Replies

4. Shell Programming and Scripting

Using a single "find" cmd to search for multiple file types and output individual files

Hi All, I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd. What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems.... (3 Replies)
Discussion started by: swaters
3 Replies

5. UNIX for Dummies Questions & Answers

Grep distinct

Hello, I have a file which looks like: %_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)****%... (5 Replies)
Discussion started by: mvalonso
5 Replies

6. 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

7. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 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. Shell Programming and Scripting

need a cmd to search starting word

example - shsk mss-sdsd-asd i need a command which will search for staring word not others it should search only -shsk cat filename | grep '-' will search whole '-' in the file but i need to search only staring '-' thank u revenna (1 Reply)
Discussion started by: revenna
1 Replies

10. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question