- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Find text throughout all files in a directory ...
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
06-23-2005 02:43 AM
06-23-2005 02:43 AM
Find text throughout all files in a directory structure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2005 02:49 AM
06-23-2005 02:49 AM
Re: Find text throughout all files in a directory structure
find /startdir -type f -exec grep -l 'text string to search for' {} \;
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2005 02:52 AM
06-23-2005 02:52 AM
Re: Find text throughout all files in a directory structure
#!/usr/bin/sh
TARGET=${1} # string to look for
shift
find . -type f | while read FNAME
do
file "${FNAME}" | grep -q -i "text"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then # is a text file of some kind
grep -q "${TARGET}" "${FNAME}"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then # match found
echo "File: ${FNAME}"
grep "${TARGET}" "${FNAME}"
fi
fi
done
--------------------------------
Use it like this:
cd to desired starting directory.
find.sh "String to look for"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2005 02:41 PM
06-23-2005 02:41 PM
Re: Find text throughout all files in a directory structure
Here is the abstract of man find
Search the two directories /example and /new/example for files containing the string "Where are you" and print the names of the files:
#find /example /new/example -exec grep -l 'Where are you' {} \;
Refer man pages for more details
#man find
Cheers!!!
eknath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2005 03:48 PM
06-23-2005 03:48 PM
Re: Find text throughout all files in a directory structure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2005 05:21 PM
06-23-2005 05:21 PM
Re: Find text throughout all files in a directory structure
i am fully agree with A.Clay and you can
use "grep" command with options -l -i ...
to search a pattern for regular file
so also Pete's reply is significant as he
uses "-type f"
Good Luck,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2005 05:24 PM
06-23-2005 05:24 PM
Re: Find text throughout all files in a directory structure
find
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 04:50 AM
07-06-2005 04:50 AM