Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using grep

Posted on 2007-03-30
13
Medium Priority
?
501 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 300 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 400 total points
ID: 18824827
grep -i searchWord `find . -name *.xml -print 2> /dev/null`
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 300 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 300 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 700 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

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…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

730 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