How to select the path that contains a certain string from a certain file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to select the path that contains a certain string from a certain file?
# 1  
Old 03-12-2009
How to select the path that contains a certain string from a certain file?

Hi,
I am new to this world of shell programming. I am facing a problem that is :
I have directory which has many sub directories at different depth. say
A/B/C/files
A/B/files
A/B/C/D/files
In this directory structure there exists a file called ".project" in some of the sub directories at any depth which contains (may not contain also )a string say "XYZ". I have to select the path of all ".project" files which contain the string "XYZ" in that directory hierarchy. It should find recursively all directories for this ".project" file
I am using find command but not able make the proper usage of it. Please help me. Thank you.
# 2  
Old 03-12-2009
Try this. I am sure this can be shortened but I am not that kind of a SME in UNIX! Smilie

Code:
find . -name *.project >> /tmp/filelist.txt
cat /tmp/filelist.txt | while read line
do
  grep "<string_to_search_for>" $line
done

HTH,Smilie

Regards,

Praveen
# 3  
Old 03-12-2009
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to select First two directory in from path name?

Can somebody help me on below question I have path and i want to select first two directory name in variable how we can do this. /Myname/xyz/yourname/abc/somebodyname i want to select /Myname/xyz in variable. Quick help will be appriciated. Thanks in advance Regards, Kumar (10 Replies)
Discussion started by: yadavricky
10 Replies

2. UNIX for Dummies Questions & Answers

select and replace only those string which is followed by \tab

Hi I have a number of sequences and a string occurs a number of times in that sequence. How can I select and replace only those strings which are followed by \tab. for eg : my sequence looks like : string0 positive cd parent=string0 id =121 string0 string0 negative ef parent=... (2 Replies)
Discussion started by: sonia102
2 Replies

3. Shell Programming and Scripting

How to select the shortest path in grep search?

Hi, How can I display only one shortest path (A/B/configure)? $ grep configure file.txt A/B/configure A/B/C/configure A/B/C/D/configure Thank you. (9 Replies)
Discussion started by: hce
9 Replies

4. Shell Programming and Scripting

How to select a single string

I am learning sed/awk. So, bear with me. I have successfully created a list (based on sed) which looks like: <cl:item href="clsysrev/XTT004/XTT05064.xml" productSubtitle="animals" unitStatus="today"IR"> <cl:item href="clsysrev/XTT007/XTT08581.xml" productSubtitle="humans"... (3 Replies)
Discussion started by: alonso_canada
3 Replies

5. Shell Programming and Scripting

Find and replace string from file which contains variable and path - SH

e.g. /home/$USER/.config replace it with "" (empty) Is this possible? I think you should play a bit with sharps ## and sed:b: (2 Replies)
Discussion started by: hakermania
2 Replies

6. Shell Programming and Scripting

Remove path string from file (string contains "/")

This is the way sed -i 's/home/$USER/.config/hello_there//g' /home/$USER/.gnomerc But, as far as I saw you cannot add any "/" in the string you want to remove.... So, what should I do in order to remove this path (which contains "/") ?:confused: (7 Replies)
Discussion started by: hakermania
7 Replies

7. Shell Programming and Scripting

How to select only the most frequent instances of a variable string in a file?

I've got a web access file that I want to grep (or awk or perl or whatever will work!) out the most frequent instances of unique IP entries. Meaning the file looks something like this: I'd like to run a sort or grep (or whatever) that will only select out the lines from IP's that had the... (7 Replies)
Discussion started by: kevinmccallum
7 Replies

8. Shell Programming and Scripting

regex to select last part of a path

Hi all, I am learning the use of regular expression and I would like to know which regex can be used to select only the last part of a directory path name. Something like: /dir1/dir2/dir2 and I want to select the last /dir2 where dir2 can be any kind of string. Thanks a lot for your help.... (7 Replies)
Discussion started by: elric
7 Replies

9. Shell Programming and Scripting

Select particular string using AWK

Hi all, i searched this forum for the awk help i needed but i couldnt get any thread matching to my problem, My problem is i have a file file1 { <Server CloneID="13k6equ4c" Name="EnterpriseServicesClone2"> <Server CloneID="13k6eqvi1" Name="EnterpriseServicesClone1"> ... (7 Replies)
Discussion started by: usha rao
7 Replies

10. Shell Programming and Scripting

How To Replace A String In File With A String Containing Windows File Path

Hi, I have a file with the following contents # Lines that start with a # are comments. # # Calling TOAD like this will perform a comparison from command line : # # "C:\Program Files\Quest Software\Toad for Oracle 9.6\toad.exe" -c... (2 Replies)
Discussion started by: rajan_san
2 Replies
Login or Register to Ask a Question