[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: grep



On Sun, Jun 24, 2001 at 05:00:09PM +0200, Federico Di Gregorio wrote:
> N=10
> FILE=tuo_file/con/tutto/il/path
> GREPPATO="`head -$N $FILE | grep 'abcd'`"
> if [ "x$GREPPATO" != "x"] ; then
>    echo "Ha trovato quello che volevo..."
> fi

o anche:

  if head -$N $FILE | grep 'abcd' &> /dev/null; then
    echo "C'e'"
  else
    echo "Non c'e'"
  fi
 
Questo perche' grep restituisce come exit code 0 in caso di almeno un
match e 1 se nessuna riga del file fa match.

Ciao

-- 
Stefano "Zack" Zacchiroli <zack@cs.unibo.it> ICQ# 33538863
Home Page: http://www.students.cs.unibo.it/~zacchiro
Undergraduate student of Computer Science @ University of Bologna, Italy
	                - Information wants to be Open -

Attachment: pgpVR6sn3l2eb.pgp
Description: PGP signature


Reply to: