?
Solved

How to print output of grep

Posted on 2008-06-13
3
Medium Priority
?
893 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
[X]
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
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
A simple overview of the possibilities of using technology for project management.
Progress
Starting up a Project

762 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