- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Pattern Searching
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-28-2002 11:48 AM
08-28-2002 11:48 AM
For example;
Iam looking for disabled accounts in a HP trusted host. These accounts are found in /tcb/files/auth/
I want to search for 'u_lock' in the various files in the directories under /tcb/files/auth
Can anybody please give me a solution since my knowledge of scripting is bad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 11:55 AM
08-28-2002 11:55 AM
Re: Pattern Searching
find /tcb/files/auth -type f -exec grep u_lock {} \;
OR
find /tcb/files/auth -type f | xargs grep u_lock
That xargs might need some other parameter...
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 11:56 AM
08-28-2002 11:56 AM
Solution#!/usr/bin/sh
TARGET="${1}"
shift
find . -type f | while read X
do
grep -q "${TARGET}" ${X}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "File: ${X}"
grep "${TARGET}" ${X}
fi
done
Use it like this:
1) cd to desired directory
2) find.sh u_lock
This will then descend the filetree at that point and list all files which contain the target phrase and the lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 12:02 PM
08-28-2002 12:02 PM
Re: Pattern Searching
This will find all files contained within the /tcb/files/auth directory (and any subdirectories). Notice that the wildcard * is enclosed in single quotes. The output of the find is sent to a grep with a -i (case insensitive) and -l (ell) switch. The -l swich is necessary as this causes the grep to return the name of the file in which the search text was found (as opposed to simply returning a copy of the line itself).
In the above example, I have searched for the string 'u_lock' (note the single quotes again around the string) and sent the output to a file called /tmp/output_file.
HTH
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 12:11 PM
08-28-2002 12:11 PM
Re: Pattern Searching
# cd /tcb/files/auth
# cat * | grep "u_lock"
OR for a complete search on any directory:
# cd dir
# find . -type f -depth -print -exec grep "u_lock" {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 12:31 PM
08-28-2002 12:31 PM
Re: Pattern Searching
find . -type f -depth -exec grep "u_lock" {} \; -print
It prints only the files that had a successful grep, not all the files checked.
HTH
Marty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 12:51 PM
08-28-2002 12:51 PM
Re: Pattern Searching
The best answers which solved 100% of my requirement has been awarded 10 points...
NO POINTS WILL BE AWARDED TO THE ANSWERS POSTED HEREAFTER....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 01:28 PM
08-28-2002 01:28 PM
Re: Pattern Searching
be careful with those "grep"s onto binary files!
cd /dir-to-start-from
find . -type f -print |
while read name; do
case "$(file $name)" in
*text*) grep "u_lock" $name /dev/null ;;
esac
done
This will only try to "grep" onto textfiles... Imagine running one of the *other* find/grep combinations, and there would be a file containing the binary codes to lock your keyboard close to "u_lock" (or some even more dangerous combinations, like instructing your terminal to *believe* you have just entered "rm -rf /* \n" or such)!
N/A=0 points, please (as announced), but I do want you to be careful ;-)
Wodisch