Solved

Using grep

Posted on 2007-03-30
13
495 Views
Last Modified: 2013-12-06
Might you know the Unix command that "would not display" the directories for which the following grep command, shows "find: cannot open /directory/etc"

This is my grep command:
grep -i searchWord `find . -name *.xml -print`
0
Comment
Question by:wemtz
  • 4
  • 2
  • 2
  • +3
13 Comments
 
LVL 25

Assisted Solution

by:Cyclops3590
Cyclops3590 earned 75 total points
ID: 18824527
the -v switch
grep -v -i searchWord `find . -name *.xml -print`
0
 
LVL 84

Expert Comment

by:ozo
ID: 18824800
find . | grep ^find:
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 100 total points
ID: 18824827
grep -i searchWord `find . -name *.xml -print 2> /dev/null`
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 25

Expert Comment

by:Cyclops3590
ID: 18825121
oops, misunderstood the question.  I read it quick and thought you were going for inverting the printed results.
0
 
LVL 19

Expert Comment

by:jools
ID: 18825701
do you have permissions to access /directory/etc?
0
 

Author Comment

by:wemtz
ID: 18826246
jools, do I have permission....NO.  I'm sure if I was root, maybe I could access all of the directories.
0
 
LVL 19

Assisted Solution

by:jools
jools earned 75 total points
ID: 18826560
So you don't want to see the errors?

Try;
grep -i searchWord `find . -name *.xml -print` 2>/dev/null
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 75 total points
ID: 18834047
The more common way of writing this is

find . -name "*.xml" -exec grep -i searchWord {} \; 2>/dev/null
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 175 total points
ID: 18835343
Tintin's suggestion improved to work on any shell on any *x ;-)
sh -c 'find . -type f -name "\*.xml" -exec grep -i searchWord {} \; 2>/dev/null'
0
 
LVL 19

Expert Comment

by:jools
ID: 18840022
Sorry Guys, I just reread and saw ozo's answer! I didn't see it before honest!

I don't mind if points are changed (if thats possible!)

Just in case you were wondering the 2> redirects all errors (stderr), in this case it sends them to null (think trash).

J
0
 
LVL 19

Expert Comment

by:jools
ID: 18841675
Thanks,

Apologies wemtz, you may have missed the ozo response as well, would you please be so kind as to regrade, I won't moan again.

Cheers All.
0
 

Author Comment

by:wemtz
ID: 18846504
jools, I do not understand your request.  I will include everyone when I issue the points.
thanks
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS- KeepAlived notify script not working 23 79
linux redhat 7.2 10 70
awk variable in printf 1 22
Field name with special character (Ñ) in Oracle 11 45
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

813 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now