[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

grep grep grep end again grep

Posted on 2005-04-15
11
Medium Priority
?
438 Views
Last Modified: 2012-06-27
OS Windows
I'm using Grep for Windows (CygWin) and problem is:
Nead to  search only for txt & xml files but recursive through directories ( with -r option).
how can i specify taht becouse this (grep -r  -pattern C:/something/*.txt) search only in that directory , -r option dont work. I can search all end filter results in php but then it search about 80% more files. Is there any option in grep command where i can specify file format. Something like -fileformat .txt, .xml .....  or anybody  knows how to do it.

0
Comment
Question by:milankuzmanovic
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 19

Expert Comment

by:Barthax
ID: 13790320
I would expect the problem lies in the fact you using your "C:/something" directory as the current working directory.  Try changing directory to there before issuing "grep -r pattern *.txt").
0
 
LVL 19

Expert Comment

by:Barthax
ID: 13790339
Sorry, that should have been [...]"C:/something" and not the current working directory.[..]
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13790413
I think there is an approach that goes something like

find something -name *.txt | xargs grep searchtextpattern

Check out the man pages on 'find' and 'xargs'.

JP
0
Independent Software Vendors: 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!

 
LVL 6

Expert Comment

by:alextr2003fr
ID: 13790565
if you are trying to look in a windows file structure then why you use *nix paths? simply try c:\something\ instead
0
 
LVL 6

Expert Comment

by:alextr2003fr
ID: 13790674
and AFAIK under windows you should rather use something like :  grep -S "searchtext" \somepath\files\*.txt
0
 

Author Comment

by:milankuzmanovic
ID: 13791636
Whatever i tried it works fine but  recursive option ( -r ) have no effects.
Next is wrong
grep -options "pattern(s)" [path]*.txt
Maybe xargs and find would do something.
And for alextr2003fr  i dont have -S option, only -s if you tought -S as option


0
 
LVL 6

Expert Comment

by:alextr2003fr
ID: 13791700
what version of grep is it?
0
 

Author Comment

by:milankuzmanovic
ID: 13791831
CygWin grep
It's more than grep practically it's linux on windows. You can download thousands of libraries.
I need to call him from php page with $fp = popen($cmdstr, "r");
0
 
LVL 19

Accepted Solution

by:
Barthax earned 500 total points
ID: 13791905
I seem to recall there being some versions of grep which require the -r at the end.  I know for some reason I got into the habit of grep <pattern> <filemask> -r for a while - I can't remember the reason I had for it though!

Another possibility, in your php, try using a "chdir('path'); " before the call to popen(...).

grep -S <etc> is the DOS compilation, IIRC.  CygWin is effectively, as milankuzmanovic indicates, Linux under Windows.
0
 

Author Comment

by:milankuzmanovic
ID: 13792011
-r at the end is correct
chdir('path') is not problem
Grep is very exelent tool but there is no good manual with things like "-r on end" and
i need to make some search with grep with search from date to date, non matching, exact phrase, all words etc all in one query.  and this was to much.

Thanks.
0
 
LVL 7

Expert Comment

by:jdpipe
ID: 13802871
I would definitely look at coupling 'grep' with 'find' if you have a complex file query to make. Cygwin/*nix commands are designed to be piped together for added power, often one command acting aloe will not be enough.

JP
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 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