- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Want to find files which contains a string fr...
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
04-13-2003 08:57 PM
04-13-2003 08:57 PM
Want to find files which contains a string from current directory
I want to find files which contains a string from current directory.
What is the command for this ?
Thanks
R.Ezhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2003 09:10 PM
04-13-2003 09:10 PM
Re: Want to find files which contains a string from current directory
$ find . -exec grep "
Script -
#!/usr/bin/ksh
for file in `find .`
do
if [[ `file $file` = "$file: ascii text" ]]; then
grep "
fi
done
#EOF
Use -ok instead of -exec to prompt you before searching a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2003 09:11 PM
04-13-2003 09:11 PM
Re: Want to find files which contains a string from current directory
$grep "string to be found" *
list all the files in the current directory containing the string "string to be found"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2003 09:11 PM
04-13-2003 09:11 PM
Re: Want to find files which contains a string from current directory
I'm assuming your attempting to find all files that have the text string 'test':
$ grep -i string *
If this i not what you looking for, please give us some additional information.
Regards
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2003 09:14 PM
04-13-2003 09:14 PM
Re: Want to find files which contains a string from current directory
grep "string" *
should do fine.
If you have binary files (compiled code, libraries, etc) then you could do
grep -l "string" file
would list the file with matching textm without dumping long lines of binary output on your terminal screen.
You could also set up a loop and process files using the strings command:
for i in `ls`; do if strings $i | grep -q "string"; then printf "$i: "; strings $i | grep "string"; fi; done
This will print the name of each file and the natching text ("string") in your current directory.
Explanation:
for i in `ls`; do -
get a list of files in the current directory and assign to $i variable for each pass though the loop.
if strings $i | grep -q "string" -
Test for presence of string "string" in file. Use -q options on grep to set return code without printing any output.
printf "$i: "; strings $i | grep "string" -
Print file name, and any strings found that match "string"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2003 09:16 PM
04-13-2003 09:16 PM
Re: Want to find files which contains a string from current directory
$ find . | xargs grep "
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2003 09:33 PM
04-13-2003 09:33 PM
Re: Want to find files which contains a string from current directory
It's a good practice to assign points (part of itrc forums etiquette) to responses.
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2003 04:57 AM
04-15-2003 04:57 AM
Re: Want to find files which contains a string from current directory
If you are looking for something in a compiled program here is my quick and dirty.
find . -exec strings {} \;| grep
Tim