- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep to show filename
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
07-17-2007 11:00 AM
07-17-2007 11:00 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2007 11:16 AM
07-17-2007 11:16 AM
Re: grep to show filename
do
strings -a $file | grep my string > /tmp/log$$
if [ $? -eq 0 ]
then
echo "$file has" `cat /tmp/log$$`
>/tmp/log$$
fi
done
rm -rf /tmp/log$$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2007 11:24 AM
07-17-2007 11:24 AM
Re: grep to show filename
One way:
cd /path
for F in `ls -1`
do
echo "[ $F ]"
strings $F|grep pattern
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2007 03:08 PM
07-17-2007 03:08 PM
Re: grep to show filename
Because to grep the file is a pipe and stdin.
>JRF: echo "[ $F ]"
The problem with this is that it always produces output whether there is a match. Most times when I'm lazy, I do the same thing. Especially if you use: echo "Doing $F =======",
so you can see the names and the strings.
If I want something foolproof, you need something like Kaps01's, where it echos only if it finds it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2007 05:36 PM
07-17-2007 05:36 PM
Re: grep to show filename
What about:
$ grep -l mystring *.xxx
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2007 05:51 PM
07-17-2007 05:51 PM
Re: grep to show filename
Dave said they were binary files and that's why strings -a was used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 01:06 AM
07-18-2007 01:06 AM
SolutionOK, here's a way to avoid temporary files, superfluous output, and multiple processes:
By example, suppose you wanted to find "UNIX" in several binary files. You can do:
# perl -nle 'BEGIN{use open IO=>":raw"};while (/([\040-\176\s]{4,})/g) {$p=$1;print $ARGV,":",$p if $p=~/UNIX/}' /usr/bin/date /usr/bin/cp /usr/bin/mv
/usr/bin/date:UNIX95
/usr/bin/cp:UNIX95
/usr/bin/cp:UNIX95
/usr/bin/mv:UNIX95
This Perl script emulates 'strings'. Change the pattern to match whatever you want. Pass one or more filesnames or let the shell expand a glob like "*.xxx" instead. You can add 'i' for case-insensitive matches if you want. Thus, to find the pattern "mystring" case-insensitively, change:
$p=~/UNIX/}
to:
$p=~/mystring/i}
Regards!
...JRF...