Register
It is currently Thu Aug 21, 2014 6:06 am

File Locator


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Fri Dec 30, 2011 10:16 pm   

Joined: Fri Dec 30, 2011 10:03 pm
Posts: 4
Hello,
I'm hoping someone can help me with a script that will search multiple directories for any files called submake.sun.mk, do a more on that file and finally pipe the results along with the directory name to a text file. I am new to bash script writing so any help would be very much appreciated.

1. Capture the name of all directories which contain a file called submake.sun.mk
2. Do a "more" on the submake.sun.mk contained within each of the directories.
3. Capture the results of the "more"
4. Pipe the directory name along with the results item 3 to a text file.

Thank you in advance for your help.


Top
 Profile  
 PostPosted: Fri Dec 30, 2011 10:28 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
hi

Quote:
capture
are you thinking with a mouse in your hand as a brain? :)

more is not the right tool to do such a thing, at least cat could be.

you should read the find command's man page.

show an example of what should be done, the way you explain is not clear (you can't pipe a name).


Top
 Profile  
 PostPosted: Wed Jan 04, 2012 1:12 pm   

Joined: Fri Dec 30, 2011 10:03 pm
Posts: 4
I apologize for not being very clear and will describe in more detail what I am trying to accomplish. There are about 200 sub-directories within a mount called /dir1/dir2/dir3/. Within each one of these sub-dirs, there is a file called submake.sun.mk. I am able to cd into these sub-directories and do a $ grep ^SZ_CUST_PATH= submake.sun.mk which successfully provides me with the answer I need for that particular directory. This is of course a very tedious process so I need a script that will capture the name of each sub-directory as well as the result of the grep statement for that directory and the submake.sun.mk within that directory. Ideally, I would like the sub-dir name and grep result to be formatted to a text file. Unfortunately, all I have been able to do thus far is figure out how to do the grep. Any assistance is again very much appreciated.


Top
 Profile  
 PostPosted: Thu Jan 05, 2012 11:42 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
hi,

tedious, like having to read a one block description? ;)

Try this
Code:
find /dir1/dir2/dir3/ -type d -exec \grep -H '^SZ_CUST_PATH=' {}/submake.sun.mk \;
that 'll find every directory under /dir1/dir2/dir3/, and grep <directory_found>/submake.sun.mk file for '^SZ_CUST_PATH'

The output will be
/dir1/dir2/dir3/<directory_found>/submake.sun.mk: <match>

Is it the format you want to be redirected to a "log" file?


Top
 Profile  
 PostPosted: Fri Jan 06, 2012 12:54 pm   

Joined: Fri Dec 30, 2011 10:03 pm
Posts: 4
I have to tell you that you have absolutely made my week! I just tried it and it works great. In terms of the format, ideally I would like the results to create a *.csv or file in which one column is the directory path and name and another column is the grep result.

Again, thank you so much for your assistance on this!


Top
 Profile  
 PostPosted: Mon Jan 09, 2012 2:41 pm   

Joined: Fri Dec 30, 2011 10:03 pm
Posts: 4
I apologize for the newbie question but I'm having difficulty determining the purpose of {}/ in the find statement that you provided me. Can you please explain its purpose. I'm hoping that if I can understand this it will help me figure out how to separate the find results into two different columns, one for the directory and one for the grep result.

Thank you in advance.


Top
 Profile  
 PostPosted: Mon Jan 09, 2012 6:42 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
{} stands for what would return find, that is, here, directories names.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP