🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #6935

Re: Consulta Shell

#6935
From: Pascal Bourguignon
Date: Sat, 26 Apr 2003 16:25
56 lines
2183 bytes
Miguel <nospam@nospam.com> writes:

> Hi,
> 
> > 
> >   while  ! final fichero; do
> >         read word
> > 
> >        if [ $word ] = $Parametro then   -lo que sea
> >        fi
> > 
> >   done
> > 
> 
> Hay varias formas de hacerlo, un par de ellas:
> 
> -------8<--------8<-------
> for i in `cat nombre_fichero`
> do
>   if [ "$i" = "$1" ]; then
>      echo "Encontrado $i"
>   fi
> done
> -------8<--------8<-------
> for i in `grep ^$1$ nombre_fichero`
> do
>   echo "Encontrado $i"
> done
> -------8<--------8<-------

Eso no funciona cuando el archivo  contiene mīŋŊs palabras que lo que el
shell puede tomar (10000 o algo asi).


while read line ; do
    for word in $line ; do
        if [ "$word" = "$parametro ] ; then 
            lo_que_sea
        fi
    fi
done < fichero

o quizas mejor:

tr ' ' '\012' < fichero | while read word ; do
        if [ "$word" = "$parametro ] ; then 
            lo_que_sea
        fi
done



-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.
Technical Details
Message-ID: <87znmdusy5.fsf@thalassa.informatimago.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail
References: <994c040b.0304260633.1c483839@posting.google.com> <b8e9jk$n5n$1@nsnmrro2-gest.nuria.telefonica-data.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f86c8,259688ac6331c8d0
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-04-26 09:25:25 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail
From: Pascal Bourguignon <spam@thalassa.informatimago.com>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Consulta Shell
Date: 26 Apr 2003 18:25:22 +0200
Organization: informatimago.com
Lines: 56
Message-ID: <87znmdusy5.fsf@thalassa.informatimago.com>
References: <994c040b.0304260633.1c483839@posting.google.com> <b8e9jk$n5n$1@nsnmrro2-gest.nuria.telefonica-data.net>
NNTP-Posting-Host: thalassa.informatimago.com (195.114.85.194)
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: fu-berlin.de 1051374323 9445225 195.114.85.194 (16 [41911])
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50