🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Consulta Shell

#7048
From: Pascal Bourguignon
Date: Sat, 12 Apr 2003 23:58
52 lines
2615 bytes
triatlonn@terra.es (Stanley) writes:

> Gracias Pere y Pascal.
> 
> He conseguido hacer un bucle que me visualiza las lineas y me dice los
> caracteres por linea. Pero ahora quiero que me cuenta las palabras que
> tienen 1-cararcter  2-caracteres  3-caracteres y m�s caracteres, para
> cada linea.
> 
> Que al final me diga:
> 
> 1-linea  1c-xx   2c-xx   3c-xx   Resto-xx
> 2-linea  1c-xx   2c-xx   3c-xx   Resto

�Hace falta leer la p�gina de manual de bash!

man bash


#!/bin/bash
fichero="$1"  # usa doble-quotes por si el nombre contiene espacios.
if [ -f "$fichero" -a -r "$fichero" ] ; then # man test 
    echo "fichero correcto"
    numlinea=0
    while read linea ; do
        numlinea=$(( $numlinea + 1 ))
        uno=0
        dos=0
        tre=0
        res=0
        for word in $linea ; do # �no " aqu�!
            case ${#word} in 
            1) uno=$(( $uno + 1 )) ;;
            2) dos=$(( $dos + 1 )) ;;
            3) tre=$(( $tre + 1 )) ;;
            *) res=$(( $res + 1 )) ;;
            esac
        done
        printf "%03d-%03d  1c-%02d  2c-%02d  3c-%02d  Resto-%02d\n" \
               $numlinea ${#linea} $uno $dos $tre $res
    done < "$fichero"
    echo "numero de lineas total: $i"
else
    echo "$fichero no es un fichero o no se puede leer."
fi



-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.
Technical Details
Message-ID: <87ptnrl143.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.0304111350.414087f7@posting.google.com> <slrnb9ej5k.114.ppujalARROBA@hola.fou.net> <8765pk9w43.fsf@thalassa.informatimago.com> <994c040b.0304121455.65edbb1b@posting.google.com>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,a25bc7d3540e92c3
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-04-12 16:58:26 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: 13 Apr 2003 01:58:20 +0200
Organization: informatimago.com
Lines: 52
Message-ID: <87ptnrl143.fsf@thalassa.informatimago.com>
References: <994c040b.0304111350.414087f7@posting.google.com> <slrnb9ej5k.114.ppujalARROBA@hola.fou.net> <8765pk9w43.fsf@thalassa.informatimago.com> <994c040b.0304121455.65edbb1b@posting.google.com>
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 1050191905 13378165 195.114.85.194 (16 [41911])
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50