- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Unix 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
01-10-2005 03:19 AM
01-10-2005 03:19 AM
Unix Grep
Hi,
I need to search for a string through out
my system. i.e as soon as i login my unix box,
i reach my home directory. From there , i need
to issue a search command which needs to search all scripts (*.sql, *.sh, *.log etc..) under all directories and sub directories.
home_dir > grep "ADFH Script Failed"
Can anyone let me know , what command should i issue.
Thanks
Jil
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 03:28 AM
01-10-2005 03:28 AM
Re: Unix Grep
TARGET="ADFH Script Failed"
find . -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \) | while read X
do
grep -q "${TARGET}" ${X}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "${X}"
fi
done
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 03:41 AM
01-10-2005 03:41 AM
Re: Unix Grep
I copied your script into a shell script(search.sh) and executed it from my home directory.
It returns only "search.sh" contains the target.I know that the traget string which i mentioned is also available in one of the subdirectory, which is not returned by this script.
Thanks
Jil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 03:50 AM
01-10-2005 03:50 AM
Re: Unix Grep
find will not traverse symbolic links unless you add the option "-follow"
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 03:58 AM
01-10-2005 03:58 AM
Re: Unix Grep
find / -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \) | while read X
I am wondering why you need to search the whole "system" since you'll be re-grepping the same files over and over and wouldn't need to be.
Anyway you could limit your search to specific directories, or at least files that with a recent modification date?
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 04:00 AM
01-10-2005 04:00 AM
Re: Unix Grep
As with all scripting, it's best to break apart the commands to see if they are doing what you think they are. I would try the find command by itself to see if it is returning the list of files matches the criteria first.
find . -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \)
If that works then you need to look at the grep command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 04:07 AM
01-10-2005 04:07 AM
Re: Unix Grep
For eg:
These are the directories and subdirectories in my system.
home_dir >
home_dir/one >
home_dir/one/one_a >
home_dir/two >
home_dir/two/two_a >
When i issue a search command from
home_dir >
It has to search home_dir >
then
home_dir/one >
then
home_dir/one/one_a >
etc......
Why would it search again and again the same directories ?
Thanks
Jil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 04:38 AM
01-10-2005 04:38 AM
Re: Unix Grep
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 04:41 AM
01-10-2005 04:41 AM
Re: Unix Grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 04:41 AM
01-10-2005 04:41 AM
Re: Unix Grep
But thats my requirement. Needs to
search all directories and subdirectories under my home directory.
Can anyone help with code ?
Thanks
Jil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 04:58 AM
01-10-2005 04:58 AM
Re: Unix Grep
I'm not sure which file would have the string which i'm searching for. Hence i'm planning to start the search from my home directory.
Thats why i couldnt "Limit to set of directory"
How can limit to set of directory ?
Thanks
Jil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 05:04 AM
01-10-2005 05:04 AM
Re: Unix Grep
This will sequentially search /dir1 (and all subdirectories) then /dir2 (abd subdirectories) then /dir3/xxx and so on.
Man find for details.
If you are unsure, then you can simply find / but be aware of the load you are imposing on the system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2005 03:56 AM
01-11-2005 03:56 AM
Re: Unix Grep
I use something similar to this when I'm looking for a text string in a list of directories. You obviously need the correct search/read permissions to do this:
find . -follow -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \) -exec grep -il '
find
. :from this direction
-follow :follow all symbolic links
-type f :find only regular files
\( -name ... -o \) :matching an OR of these regular expressions
-exec :execute the following command
grep -il '
2>/dev/null :stderr to /dev/null
You can place this is a 'for' loop to execute more commands on the resulting files.
Regards,
PK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2005 04:56 AM
01-11-2005 04:56 AM
Re: Unix Grep
Do you need to 'see' the matches, or just know which files might match. Fo rthe latter:
find . -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \) -exec grep -l "ADFH Script Failed" {} \;
Hein.