Author Topic: *IX question  (Read 1573 times)

Holly

  • Should Have Quit 500 Posts Ago
  • Posts: 1394
    • View Profile
    • The Dutton Family
*IX question
« on: February 08, 2010, 01:53:22 pm »
This is total nerdorama, so feel free to take whatever potshots are required for such a pencil-necked question. I've done what feels like an exhaustive search online, and can't quite come up with a solution, so for those familiar with working on the shell in *ix, how would you accomplish the following:

Trying to recursively locate all files which contain a pattern, and list the filenames. I have used the following to find whether there ARE files with a pattern, but haven't figured out how to modify it so that it tells me which file resulted in a match (the end result is it prints the line with the matching pattern to STDOUT, but doesn't prepend that with the name of the file, which WOULD be the case if I weren't running this through xargs):

find . -type f -name "*.*"| xargs -i grep pattern '{}'

Thanks :)
Don't put the baby in the bulldozer.

austro

  • Fantasy Team Owner
  • Illuminati
  • Posts: 19637
    • View Profile
Re: *IX question
« Reply #1 on: February 08, 2010, 02:17:38 pm »
find . -type f -name "whatever" -exec grep pattern {} /dev/null \;

The seemingly superfluous inclusion of /dev/null convinces grep that it's working with multiple files, which causes it to prepend the file name on any hits.
I remember all the good times me 'n Miller enjoyed
Up and down the M1 in some luminous yo-yo toy
But the future has to change - and to change I've got to destroy
Oh look out Lennon here I come - land ahoy-hoy-hoy

sporadic

  • Should Have Quit 500 Posts Ago
  • Posts: 1954
    • View Profile
Re: *IX question
« Reply #2 on: February 08, 2010, 02:37:20 pm »
damn my luck...the one time I forget to bring my Ovaltine decoder ring to work, this thread appears

MikeyBoy

  • Key Member of the Conspiracy
  • Posts: 2572
    • View Profile
Re: *IX question
« Reply #3 on: February 08, 2010, 02:41:45 pm »
damn my luck...the one time I forget to bring my Ovaltine decoder ring to work, this thread appears

I got your back.

find . -type f -name "whatever" -exec grep pattern {} /dev/null \; = Be sure and drink your Ovaltine
"Buenos Dias, shitheads."

Holly

  • Should Have Quit 500 Posts Ago
  • Posts: 1394
    • View Profile
    • The Dutton Family
Re: *IX question
« Reply #4 on: February 08, 2010, 02:57:54 pm »
Thanks, that did the trick!
Don't put the baby in the bulldozer.