|
|
|
|
|
|
| Author |
Message |
Stephane Chazelas *nix forums Guru
Joined: 23 Sep 2005
Posts: 490
|
Posted: Mon Jan 09, 2006 7:09 pm Post subject:
Re: Emulating egrep with sed
|
|
|
On Mon, 9 Jan 2006 23:20:41 +1100, Gyruss wrote:
| Quote: | Hi,
Given that the sed could output a multiline string when $OUTFILE has
multiple errors, is the code below acceptable? I mean is it ok to capture
a multiline string in a single variable if I just want to test whether or
not the string is null.
Cheers!
RESULT=`sed -e '/error/b' -e '/coredump/b' -e '/exception/b' -e d $OUTFILE`
|
Write it:
RESULT=`
sed -e '/error/q' -e '/coredump/q' -e '/exception/q' -e d < "$OUTFILE"
`
So that only the first matching line is returned and the
remaining not even processed (having a multiline result is not a
problem though).
| Quote: |
if [ -n $RESULT ] ; then
|
That should be:
if [ -n "$RESULT" ]; then
remember that leaving a variable expansion unquoted in shell has
a very special meaning.
| Quote: | echo "Oh no!"
else
echo "Success"
fi
|
You could do:
if
awk '/error/ || /coredump/ || ... {
found = 1
exit
}
END {
exit (1 - found)
}' < "$OUTFILE"; then ...
--
Stephane |
|
| Back to top |
|
 |
Hubble *nix forums beginner
Joined: 28 Nov 2005
Posts: 41
|
Posted: Mon Jan 09, 2006 3:38 pm Post subject:
Re: Emulating egrep with sed
|
|
|
| Quote: | I mean is it ok to capture
a multiline string in a single >variable if I just want to test whether or
not the string is null.
|
| Quote: | RESULT=`sed -e '/error/b' -e '/coredump/b' -e '/exception/b' -e d $OUTFILE`
if [ -n $RESULT ] ; then
...
Depends on your problem. If you know for sure that OUTFILE always |
contains only a few lines, this is ok. If OUTFILE can span MBytes or
GBytes, certainly not ok.
Hubble. |
|
| Back to top |
|
 |
Gyruss *nix forums beginner
Joined: 09 Jan 2006
Posts: 1
|
Posted: Mon Jan 09, 2006 12:20 pm Post subject:
Emulating egrep with sed
|
|
|
Hi,
Given that the sed could output a multiline string when $OUTFILE has
multiple errors, is the code below acceptable? I mean is it ok to capture
a multiline string in a single variable if I just want to test whether or
not the string is null.
Cheers!
RESULT=`sed -e '/error/b' -e '/coredump/b' -e '/exception/b' -e d $OUTFILE`
if [ -n $RESULT ] ; then
echo "Oh no!"
else
echo "Success"
fi |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Tue Jan 06, 2009 10:33 am | All times are GMT
|
|
McDonalds | Bad Credit Credit Cards | Personal Loans | Loans | Carrinhos para bebĂȘ
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|