- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: search for string
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
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
03-27-2006 11:03 PM
03-27-2006 11:03 PM
search for string
I need to search through all the files on my server and produce a list of only those files that contain the text FPRD within the file. I want to ignore binary files, if possible.
Thanks ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2006 11:07 PM
03-27-2006 11:07 PM
Re: search for string
do
grep -q 'FPRD' ${a}
if [ "$?" -eq "0" ];then
echo "File has FPRD in it-${a}"
else
exit 1
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2006 11:28 PM
03-27-2006 11:28 PM
Re: search for string
Try the following
find ./ | while read filename
do
if test `file $filename | cut -f 2 -d ":" | grep -c text` != "0"
then
grep -l test $filename
fi
done
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2006 12:04 AM
03-28-2006 12:04 AM
Re: search for string
This will restrict your search to "text" files, grep for your token and output the name of the file(s) containing the matching tokens:
# cat ./match
#!/usr/bin/sh
# $1=directory $2=token_to_match
find $1 -xdev -type f -exec file {} \; | \
awk -v TOKEN=$2 '/text$/ {split($1,a,":");
system("grep " TOKEN " " a[1] " /dev/null")}'
exit
...run as:
# ./match path token
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2006 12:06 AM
03-28-2006 12:06 AM
Re: search for string
In a directory,
use (ls -R1) for recursive:
for afile in $(ls -1)
do
if (file $afile | grep ascii)
then
grep -in "your string" $afile
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2006 12:16 AM
03-28-2006 12:16 AM
Re: search for string
find / -type f -exec grep -l FPRD {} \;
will do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2006 10:08 PM
03-28-2006 10:08 PM
Re: search for string
cd
grep FPRD $(file *|grep text|cut -d":" -f1)
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2006 10:12 PM
03-28-2006 10:12 PM
Re: search for string
my previous reply look for FPRD in a directory only.
If you want to look for teh same on all your system:
# Search string "hello world" only in text files including subdirectories
grep "hello world" $(find ./ -name "*" -print -exec file {} \; | grep text | cut -d ':' -f 1)
HTH,
Art