- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find then pipe to grep
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
Forums
Discussions
Discussions
Discussions
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
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-19-2002 10:10 AM
08-19-2002 10:10 AM
I'm trying to search for string in all subdirectories under a parent directory. At one time I remember that:
find /parent -type f | grep -in 'string'
worked on the command line, and I forgot what system I was on. Now that I'm on an HP9000 c240 Visualize, it doesn't produce anything. The best I can do at the command line is to grep the files in one directory at a time.
Now, if I script it, and set a shell variable to the 'find' output, there are "too many words" set to that variable because there are a lot of files to go through. I think that for me, scripting would be the way to go, so an immediate solution would be obtained if I knew how to 'find' only the files in the current directory without going into the subdirectories. Yes, 'll -1F' does it but I still then have to ignore the directories.
And yes, any solution is appreciated.
Thanks,
-Cody
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 10:14 AM
08-19-2002 10:14 AM
Re: find then pipe to grep
will do the trick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 10:14 AM
08-19-2002 10:14 AM
Re: find then pipe to grep
Try this:
# find
which will list all the files containing the
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 10:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 10:18 AM
08-19-2002 10:18 AM
Re: find then pipe to grep
If you are looking for all files in a directory and all of its subdirectories, with a particular string, then you want something like:
# find /parent -exec grep -l 'string' {} \;
'find' is *intended* to recursively descend all directories in its starting path.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 10:20 AM
08-19-2002 10:20 AM
Re: find then pipe to grep
To have "find" do only 1 level, Try-
cd yourdirectory
find . -type f -path "./*" -prune -print
You can then pipe the output to grep.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 11:59 AM
08-19-2002 11:59 AM
Re: find then pipe to grep
In this case it is sometimes better to collect all filenames in a temporary file first. Then you can grep for evrything you want and as many times you want witout traversing the filesystem again.
find /parent >tmpfile
grep string tmpfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 12:25 PM
08-19-2002 12:25 PM
Re: find then pipe to grep
be careful there with "grep(1)" onto binary files (still type "f", though)...
My usual command for problems like that:
find /parent -type f -print |
while read name; do
case "$(file $name)" in
*text*) grep 'string' $name /dev/null ;;
esac
done | more
The additional file parameter "/dev/null" forces "grep" to print the file name, a colon, and then the matching line (and since /dev/null is always empty it won't disturb your output).
Just my $0.02,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 12:55 PM
08-19-2002 12:55 PM
Re: find then pipe to grep
"find /
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 01:01 PM
08-19-2002 01:01 PM
Re: find then pipe to grep
I have some older systems that do nothing if you dont give a -print
I.E. find /etc -name hosts
#
find /etc -name hosts -print
hosts
#
Other systems find commands will complain about a missing verb if -find or -exec are not given.
You can also use the -exec embedded in your command...
find / -exec /bin/grep -i -n string {} \;
Hope it helps
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2002 10:09 AM
09-12-2002 10:09 AM
Re: find then pipe to grep
Just a reminder to give points out to those who answered your questions. It only takes a moment, and helps make the forums more useful to everyone.
Sean