Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to print output of grep

Posted on 2008-06-13
3
888 Views
Last Modified: 2013-11-26
I have attached a code snippet so you can see what I'm doing.

What I have is a directory filled with other directories and files containing .svn and .class.php files.

I need to come up with a way to determine if any of these files are being referenced in any of the other files.
This means I must grep through the files to find the string Filename.class.php but paths containing .svn should be ignored.

My comments indicate exactly my needs. But the code doesn't do exactly what they say. For instance,
set $file=$(ls -R1 |egrep -e '\.class\.php$') only gets the filename and not the directory/filename.

Thanks!
#!/bin/bash
 
cd public_html/dd/
# Get the full path of the file
set $file=$(ls -R1 |egrep -e '\.class\.php$')
 
while [ $file ]
do
	# Ignore .svn directories 
	set $result=$(grep "$file" *.class\.php)
	# Only print resultant files not in a .svn directory
done

Open in new window

0
Comment
Question by:rae_rae
  • 2
3 Comments
 
LVL 3

Author Comment

by:rae_rae
ID: 21782818
Thinking on this a bit, it really does make more sense to get a list of path/file for each file that is not in a .svn directory and that is not found being called in any of the other files within the list.

Perhaps this helps some to figure out how to tackle this problem.
Also, consider that a script like this would be great for any developer who is working on a large project to use as a method to sweep for dead pages/code. :)
0
 
LVL 2

Expert Comment

by:jml948
ID: 21784648
whenever i am searching for something specific in linux i use the following:

find - type f -exec grep -H "text here" "{}" \;

So in "text here" you could replace it with ".class.php"

Good Luck.
0
 
LVL 3

Accepted Solution

by:
rae_rae earned 0 total points
ID: 21868261
Thanks jm,
I'm looking into other solutions.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

5 Tips For Long Jumpers: A Sprinter's Approach to Agile Software Development As a Sprinter, long jumping — applying momentum to progress by leaps and bounds — is a natural and complementary skill. In the following article, I will share my five ti…
3 Tips For Quarter Milers: A Sprinter's Understanding of Agile Software Development Two years ago, I wrote a blog entry about Agile software development (http://www.experts-exchange.com/blogs/mwvisa1/B_1770-Agile-Software-Development.html). At th…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question