Solved

Using grep

Posted on 2007-03-30
13
497 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Hosting 16 80
Linux mount of Windows Shared Now Fails 8 118
Can't connect to FTP 18 110
Understanding ping command in Ubuntu 5 34
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

726 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