Solved

Using grep

Posted on 2007-03-30
13
500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

631 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