Solved

How to print output of grep

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A decent free and collaborative gantt chart (project planner) 3 502
Scrum task and User story 2 172
MS project 2013 - 13 hours days no overtime 5 91
Project roadmap 4 76
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
Read about the ways of improving workplace communication.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

739 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