Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:26:27+00:00 2026-05-22T15:26:27+00:00

This is the command I’ve been using for finding matches (queryString) in php files,

  • 0

This is the command I’ve been using for finding matches (queryString) in php files, in the current directory, with grep, case insensitive, and showing matching results in line:

find . -iname "*php" -exec grep -iH queryString {} \;

Is there a way to also pipe just the file name of the matches to another script?

I could probably run the -exec command twice, but that seems inefficient.

What I’d love to do on Mac OS X is then actually to “reveal” that file in the finder. I think I can handle that part. If I had to give up the inline matches and just let grep show the files names, and then pipe that to a third script, that would be fine, too – I would settle.

But I’m actually not even sure how to pipe the output (the matched file names) to somewhere else…

Help! 🙂

Clarification

I’d like to reveal each of the files in a finder window – so I’m probably not going to using the -q flag and stop at the first one.

I’m going to run this in the console, ideally I’d like to see the inline matches printed out there, as well as being able to pipe them to another script, like oascript (applescript, to reveal them in the finder). That’s why I have been using -H – because I like to see both the file name and the match.

If I had to settle for just using -l so that the file name could more easily be piped to another script, that would be OK, too. But I think after looking at the reply below from @Charlie Martin, that xargs could be helpful here in doing both at the same time with a single find, and single grep command.

I did say bash but I don’t really mind if this needs to be ran as /bin/sh instead – I don’t know too much about the differences yet, but I do know there are some important ones.

Thank you all for the responses, I’m going to try some of them at the command line and see if I can get any of them to work and then I think I can choose the best answer. Leave a comment if you want me to clarify anything more.

Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:26:28+00:00Added an answer on May 22, 2026 at 3:26 pm

    You bet. The usual thing is something like

      $ find /path -name pattern -print | xargs command
    

    So you might for example do

      $ find . -name '*.[ch]' -print | xargs grep -H 'main' 
    

    (Quiz: why -H?)

    You can carry on with this farther; for example. you might use

      $ find . -name '*.[ch]' -print | xargs grep -H 'main' | cut -d ':' -f 1
    

    to get the vector of file names for files that contain ‘main’, or

      $ find . -name '*.[ch]' -print | xargs grep -H 'main' | cut -d ':' -f 1 |
          xargs growlnotify -
    

    to have each name become a Growl notification.

    You could also do

     $ grep pattern `find /path -name pattern`
    

    or

     $ grep pattern $(find /path -name pattern)
    

    (in bash(1) at least these are equivalent) but you can run into limits on the length of a command line that way.

    Update

    To answer your questions:

    (1) You can do anything in bash you can do in sh. The one thing I’ve mentioned that would be any different is the use of $(command) in place of using backticks around command, and that works in the version of sh on Macs. The csh, zsh, ash, and fish are different.

    (2) I think merely doing $ open $(dirname arg) will opena finder window on the containing directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this command: cut -d: -f2 To sort and reedit text, Is
I've been getting this undefined symbol building with this command line: $ gcc test.cpp
I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command: echo -e doesn't print
Using this command GRANT ALL PRIVILEGES ON *.* to 'brian'@'%' identified by 'password'; I
I have this command that I run everyday via cron: find /home/get/public_html/videos -daystart -maxdepth
I am aware of this command: cvs log -N -w<userid> -d1 day ago Unfortunately
I have this command that I run every 24 hours currently. find /var/www/html/audio -daystart
When installing subversion as a service, I used this command: c:\>svnservice -install --daemon --root
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,
if I paste this into the command prompt by hand, it works, but if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.