Solved

How to print output of grep

Posted on 2008-06-13
3
877 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks jm,
I'm looking into other solutions.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Prologue Today, the Information Technology Infrastructure Library® (ITIL) is very commonly used in the IT industry for IT Service Management. It is strongly promoted by the service management industry experts. In 1980, the need for ITIL was per…
Transparency shows that a company is the kind of business that it wants people to think it is.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now