- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to search a word
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
06-29-2006 05:54 PM
06-29-2006 05:54 PM
Script to search a word
I have a text file "printout.txt" , I want to check the content this file , if the word "failure" appear in this file for over two times , then do xxxxxxxx ,
what can I do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 06:04 PM
06-29-2006 06:04 PM
Re: Script to search a word
0. Is the mere existance of the word enough to take action?
1. Is there more info on that line you need?
2. Is there more info in the surrounding lines you need?
In case 0, just use grep
if [ "`grep failure printout.txt`" == "" ]; then
echo no failure found
else
# Do some actions here
fi
If you want more security, use GNU grep and -w (grep whole word only)
If you need flexibility, use perl
#!/usr/bin/perl
use strict;
use warnings;
@ARGV = ("printout.txt");
while (<>) {
m/\b failure \b/x or next;
print STDERR "Found a failure on line $.\n";
system "echo Help | mailx -s failure you\@local.host";
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 06:16 PM
06-29-2006 06:16 PM
Re: Script to search a word
what I want is simple , if found the word "failure" appear OVER TWO TIMES in the file , then mail the message to me , what can I do ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 06:25 PM
06-29-2006 06:25 PM
Re: Script to search a word
gives you the number of the word "failure" in the file.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 06:33 PM
06-29-2006 06:33 PM
Re: Script to search a word
# perl -nle'/\bfailure\b/ and$n++}END{print$n' printout.txt
# grep -w failure printout.txt | wc -l
So, in a script, you could do
--8<---
n=`grep -w failure printout.txt | wc -l`
if [ $n -ge 3 ]; then
# actions here
fi
-->8---
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 07:10 PM
06-29-2006 07:10 PM
Re: Script to search a word
Here another shell one-liner:
# [ $(grep -c failure printout.txt) -ge 2 ] && do_xxxxxxxx
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2006 03:50 AM
07-02-2006 03:50 AM
Re: Script to search a word
Enjoy, Have FUN! H.merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2006 08:48 PM
07-02-2006 08:48 PM
Re: Script to search a word
this runs on my hp-ux 11i:
cat printout.txt
failure hgjhjhk
failured
jkjk failure
klkl
if [[ $(grep -cw failure printout.txt) -ge 2 ]]; then
echo found more them 2 failure
fi
HTH,
Art