UNIX Expert needed - grep question
I am trying to do a search on our server to find out all the occurences of the statement:
document.location
in all of our html and javascript source code.
I am using the following:
find . -type f -exec grep -l 'document.location' '{}' \; > $HOME/location1.txt
However the results returned in my output file are also bringing back any statements within the code such as document.write etc.
Can anyone help and provide me with what I should be searching for so that only files are brought back where they match document.location only.
Many thanks in advance.
document.location
in all of our html and javascript source code.
I am using the following:
find . -type f -exec grep -l 'document.location' '{}' \; > $HOME/location1.txt
However the results returned in my output file are also bringing back any statements within the code such as document.write etc.
Can anyone help and provide me with what I should be searching for so that only files are brought back where they match document.location only.
Many thanks in advance.
Thanks, I've had to take the -e out to get it to run. So far it appears to have worked.
I need to find all the pages that have a server re-direct on and the best method I have found is to look through the source code looking for document.location.
So far from the above search, all the pages that it has found, appear to re-direct to another page when viewing them, so it looks like it is working.
Thanks.
I need to find all the pages that have a server re-direct on and the best method I have found is to look through the source code looking for document.location.
So far from the above search, all the pages that it has found, appear to re-direct to another page when viewing them, so it looks like it is working.
Thanks.
Mind you the search does bring back the matches AND also if the keyword is in comments. I am looking just for the pages that will execute the statement. Don't suppose there is some clever way in the grep statement to not bring back matches where the keyword is in comments. Probably impossible as the comments begin in different places in the code from one file to another.
I suppose I need to check the returned results one by one manually to see if the source code does indeed contain the keyword in comments and if it does then just ignore them.
Unless of course someone knows something different?!?!
I suppose I need to check the returned results one by one manually to see if the source code does indeed contain the keyword in comments and if it does then just ignore them.
Unless of course someone knows something different?!?!
Well it isn't worth writing a regular expression to filter them all out. You could pipe the output through ``grep -v "\""'' before redirecting to a file but for instances where document.location isn't itself within quotes, but quotes exist elsewhere on the line, it wont pick it up.
Steve.
Steve.
Just do what any self respecting developer would do....remove all the comments and never put any more in 
Provided all commented lines begin with the comment characters shouldn't be too hard. Could be a bit of a pain though if you need to work out if it is within a comment block.

Provided all commented lines begin with the comment characters shouldn't be too hard. Could be a bit of a pain though if you need to work out if it is within a comment block.
Trending Topics
Thanks for the help on the above.
How would I go about searching within HTML files for say 4 words using the grep command.
eg look for "Credit" AND "Card" AND "Payment" AND "American".
All the above 4 words must appear within the HTML file for it to be brought back.
Thanks in advance.
How would I go about searching within HTML files for say 4 words using the grep command.
eg look for "Credit" AND "Card" AND "Payment" AND "American".
All the above 4 words must appear within the HTML file for it to be brought back.
Thanks in advance.
You obviously didn't 
for logical OR:
grep -e "(Credit|Card|Payment|American)" file
If you don't know the order in which those searchterms will be in the file(s) you have to make multiple passes and check each searched term.
I'd do this in Perl:
perl -0ne '/Credit/ && /Card/ && /Payment/ && /American/' file
Let's edit this and put it in a format you can use:
find . -name "*.html" -exec perl -0ne '/Credit/ && /Card/ && /Payment/ && /American/ && print "$ARGV\n"' {} \;
There's probably a far better way.
Steve.
[Edited by stevencotton - 7/18/2002 10:09:01 AM]

for logical OR:
grep -e "(Credit|Card|Payment|American)" file
If you don't know the order in which those searchterms will be in the file(s) you have to make multiple passes and check each searched term.
I'd do this in Perl:
perl -0ne '/Credit/ && /Card/ && /Payment/ && /American/' file
Let's edit this and put it in a format you can use:
find . -name "*.html" -exec perl -0ne '/Credit/ && /Card/ && /Payment/ && /American/ && print "$ARGV\n"' {} \;
There's probably a far better way.
Steve.
[Edited by stevencotton - 7/18/2002 10:09:01 AM]
Thread
Thread Starter
Forum
Replies
Last Post
robbie1988
Wanted
2
Sep 13, 2015 09:25 AM
The Joshua Tree
Computer & Technology Related
18
Sep 11, 2015 09:24 PM
Scooby-Doo 2
Wheels And Tyres For Sale
1
Sep 9, 2015 06:51 PM




