Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with find -exec command 1

Status
Not open for further replies.

linuxMaestro

Instructor
Jan 12, 2004
183
US
This command........
find /home/goog -name *.php -exec fgrep "$year" '{}' \; -print

gives me....
find: paths must precede expression
Usage: find [path...] [expression]

What is the correct syntax for that command?

Logic:
find in /home/goog
all files that are .php
for each php file fgrep "$year"
if line found, print output from fgrep

Thanks!
 
Place your name in express in a set of double quotes.

find /home/goog -name "*.php" -exec fgrep "$year" '{}' \; -print

If you set up the xtrace option by using set -x and then running your command odds are you would see the *.php was being search for in your current directory and not /home/goog.


HTH,

Steve
 
If you want the fgrep to display the file name
[tt]
find /home/goog -name "*.php" -exec fgrep "$year" '{}' /dev/null \;
[/tt]

Jean Pierre.
 
You can also do this, to speed up the process:
find /home/goog -name '*.php' | xargs fgrep "$year"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
When I run those it prints out all lines of the file, not just the lines containing $year.

How can I get it to print just the lines containing $year?

Thanks!
 
year="WhatYouAreSearching"
find /home/goog -name '*.php' | xargs fgrep "$year"


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks!

I put a \ in front of $

find /home/goog -name '*.php' | xargs fgrep "\$year"
 
Another way:
find /home/goog -name '*.php' | xargs fgrep '$year'

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top