- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find and xargs question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:12 AM
тАО08-27-2007 08:12 AM
I am issuing the following command :
find . -name "*"|xargs grep 3300
which gives me a listing of files having 3300 in their text but the I dont want to see log files . How to modify this command in order for me not to have log files .
I tried "find . -name "*"|xargs grep 3300|xargs grep -v *log* ( did not work )
find . -name "*"|xargs grep 3300|grep -v *log*
but this also gives me log files.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:18 AM
тАО08-27-2007 08:18 AM
Re: find and xargs question
find . -type f \( -name '*3300*' -a ! -name '*log*' \)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:24 AM
тАО08-27-2007 08:24 AM
Re: find and xargs question
if you will find the string only in the files of the current directory you can use this:
$grep 3300 $(ls | grep -v log)
Hope this helps
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:27 AM
тАО08-27-2007 08:27 AM
Re: find and xargs question
...and NOTE carefully that Clay quoted "*log*".
This prevents the shell from expanding "*log*" before 'find' sees the argument and giving you an obtuse error when failing.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:47 AM
тАО08-27-2007 08:47 AM
Solution$ find . -type f ! -name "*log*" -exec grep 3000 +
To exclude log, you must grep -v before xargs.
The problem with your "grep -v *log*", is that grep takes a regexp(5) and not a file matching pattern. And as JRF mentions, you would need to quote it, IF those "*" were required.
>Clay: find . -type f \( -name '*3300*' -a ! -name '*log*' \)
The string 3300 is in the file, not the name.
And \( -a \) aren't required.
>Oviwan: $grep 3300 $(ls | grep -v log)
While this does what you say, you can use the shell's file name generation directly:
$ grep 3300 !(*log*)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:48 AM
тАО08-27-2007 08:48 AM
Re: find and xargs question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:55 AM
тАО08-27-2007 08:55 AM
Re: find and xargs question
This worked for me -
Thanks Dennis!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 08:55 AM
тАО08-27-2007 08:55 AM
Re: find and xargs question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 09:01 AM
тАО08-27-2007 09:01 AM
Re: find and xargs question
Yes, in the filename. But you didn't want that. ;-)
>find . -name "*"|grep -v log |xargs grep "3300"
You do know you don't need "-name" above. And you can put the grep -v log into another ! -name. And you can use -exec ... + instead of xargs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 09:06 AM
тАО08-27-2007 09:06 AM
Re: find and xargs question
find . -type f ! -name '*log*' | while read F
do
grep -q "3300" "${F}"
GSTAT=${?}
if [[ ${GSTAT} -eq 0 ]] # match
then
echo "${F}"
fi
done
Now, a better test though most expensive is to first send the filename to the file command to see if it is some sort of text file before using grep. On some platforms grep will crash when fed non-text files for breakfast.
find . -type f ! -name '*log*' | while read F
do
file "${F}" | grep -q -i "text"
GSTAT1=${?}
if [[ ${GSTAT1} -eq 0 ]
then # text file; ok to grep
grep -q "3300" "${F}"
GSTAT2=${?}
if [[ ${GSTAT2} -eq 0 ]]
then # match
echo "${F}"
fi
fi
done
Note that I was careful to quote your filenames because some evil person just might have embedded whitespace in them.