Solved

How to print output of grep

Posted on 2008-06-13
3
891 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Documentation is a big contentious issue in Agile. There is a reason for this. When you start your presentation on Agile you start by going through the 4 statements of agile manifesto (https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&…
Learn how ViaSat reduced average response times for IT incidents from 10 minutes to 30 seconds.
Progress
Starting up a Project

695 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