Re: [Pour être précis] Re: grep ou awk
--- Nicolas SABOURET <Nicolas.Sabouret@limsi.fr> wrote: > Nicolas
SABOURET wrote:
> >
> > if [ grep -c "chaîne" -gt 0 ]; then ...
> >
>
> grep -c "chaine" nomfichier en fait, et entre ` (backquote) si c'est
> dans le "if".
>
> Pardon d'avoir été approximatif.
>
Je dirais même plus : étant donné que le fichier peut être très gros,
il est sûrement plus indiqué de sortir dès qu'une occurence est
trouvée, et non pas aller jusqu'à la fin pour compter toutes les
occurences (option -c).
Extrait du man de grep :
-q, --quiet, --silent
Quiet; suppress normal output. The scanning will
stop on the first match. Also see the -s or --no-
messages option below.
[...]
-s, --no-messages
Suppress error messages about nonexistent or
unreadable files. Portability note: unlike GNU
grep, traditional grep did not conform to POSIX.2,
because traditional grep lacked a -q option and its
-s option behaved like GNU grep's -q option. Shell
scripts intended to be portable to traditional grep
should avoid both -q and -s and should redirect
output to /dev/null instead.
Donc un -q me semble plus approprié dans le cas d'un grep conformant à
POSIX.2 (cas du grep GNU), ou -s pour un grep "traditionnel" ...
Le test se fait alors sur le code de sortie (stocké dans la variable
shell $?) :
Normally, exit status is 0 if matches were found, and 1 if
no matches were found. (The -v option inverts the sense
of the exit status.) Exit status is 2 if there were syn-
tax errors in the pattern, inaccessible input files, or
other system errors.
François.
=====
Francois BOTTIN
--
"How kind," the PFY sighs. "But where will I go?"
"Somewhere where they know nothing about computing...
where they wouldn't know a RAM chip from a potato chip!"
"But I don't want to visit Microsoft!" he whines.
The BOFH 1998 - Simon Travaglia (bofh.ntk.net)
________________________________________________________________
Nokia 5510 looks weird sounds great.
Go to http://uk.promotions.yahoo.com/nokia/ discover and win it!
The competition ends 16 th of December 2001.
Reply to: