- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell scripts to grep and compare strings ?? ...
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
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-13-2002 02:39 AM
06-13-2002 02:39 AM
Shell scripts to grep and compare strings ?? Any idea ?
Shell scripts like other programs should have error handling routine that in some cases help generating error messages and error codes for bug fixing and trouble shooting. Now I would like to grep some of the error code and error messages generated by the application program and compare the error messages with a configuration file with pre-defined string pattens.
However, I have difficulties in implementing a simple loop to handle all the possible string pattens. Sometimes I need to:
1. grep "xxx" filename
2. grep "xxx" filename | grep -vh "yyy"
3. grep "xxx" filename | grep -v "yyy" |head -1
4. grep "xxx" filename | sort -u
....etc.
I have try to incorporate the whole command set into the configuration file, but was in vain !! Any suggestions?? Appreciated it if anyone can help!!
Many thanks,
Chris,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:07 AM
06-13-2002 03:07 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
I have a few questions:
1.- xxx and yyy are error codes and reside in a different file or you input at runtime?
2.- How you determine what option to do?
3.- The filename is fixed or depends?
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:17 AM
06-13-2002 03:17 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
Gnana A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:27 AM
06-13-2002 03:27 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
Chris,
look at egrep or better yet fgrep.
egrep AKA "grep -e string -e string ..." allows you to put many things on one line.
fgrep AKA "grep -f fine_name_containing_patterns" allows you to have a file of patterns to search for.
If you "man grep" you will see these options.
But what you really need is perl, which will give you more than enough ability to "trap" errors. Shell scripting (ksh, csh, bash, ...) is for simple things. The more complicated tasks should be written in perl, although I even write the simple things in perl.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 05:14 AM
06-13-2002 05:14 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 05:27 AM
06-13-2002 05:27 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
The "return code" from a command string will be that of the LAST command [from a string of commands piped together "|" ]
e.g.
grep abc file1 | egrep -v x | grep a
If the second grep (grep -v x) fails the rc=1 but the last grep could then succeed and the rc=0. (I'm not 100% sure if grep -v can fail, but assume it can)
To get the return code from a string use $? variable i.e.
#!/usr/bin/ksh
grep abc file1
RetCode=$?
if [ $RetCode -eq 0 ]
then
echo "the cmd worked"
else
echo "the cmd failed***"
fi
I hope this helps
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 10:17 AM
06-14-2002 10:17 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
Thanks,
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 10:24 AM
06-14-2002 10:24 AM
Re: Shell scripts to grep and compare strings ?? Any idea ?
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 12:01 PM
06-14-2002 12:01 PM
Re: Shell scripts to grep and compare strings ?? Any idea ?
If [ $? = 0 ] ;then
echo "Command Passed"
RC=0
else
echo "Comand failed"
RC=1
fi
You can add more grep commands under failure, i.e. after Command Failed & debug with different greps & thus change the value of RC in it. This way your will get perfect Return Code, RC.
Ameet