lunes, 30 de septiembre de 2013

Ejemplos con el Comando wc

Linux > export LANG=es_ES
Linux>

Aquí está una fila:

Linux > cat file1
Increase productivity across your entire Oracle stack
with access to unique on-line tools and support
communities - all part of your Oracle Premier Support
service.
Use Oracle proactive support to reduce risks and
lower your organisations costs through preventive
maintenance. Benefit from health services, intelligent
fault management and timely, personalized advice,
backed by Oracle support experts.
Linux >

Se puede contar el número de líneas, palabras y carácteres en la fila de la manera siguiente:

Linux > wc file1
      9      56     403 file1
Linux >

Si solamente necesitas el número de líneas, aquí está lo que debes hacer:

Linux > wc -l file1
      9 file1
Linux >

El ejemplo siguiente cuenta las palabras en la fila:

Linux > wc -w file1
     56 file1
Linux >

Con wc -c se puede contar el número de carácteres en la fila:

Linux > wc -c file1
    403 file1
Linux >

Se puede hallar la longitud de la línea más larga así:

Linux > wc -L file1
     54 file1
Linux >

Aquí está otra fila:

Linux > cat file2
The 2012 threat landscape is one of constant and rapid
change.
Where new website vulnerabilities are tirelessly sought
and exploited.
Where new social engineering techniques can increasingly
circumvent external security measures and infect from
within.
And where hackers now employ multiple attack
methodologies and vectors to penetrate defences and
steal information.
Linux >


Es posible dar los nombres de más de una fila así:

Linux > wc -lc file1 file2
      9     403 file1
     10     369 file2
     19     772 total
Linux >

En el ejemplo siguiente, empleamos cat para ver el resultado sin el nombre de la fila:

Linux > cat file1|wc -L
     54
Linux >

Si das el nombre de una fila que no existe, wc responde con un mensaje apropiado:

Linux > wc file3
wc: file3: No existe el fichero o el directorio
Linux >


En inglés / in English 

lunes, 23 de septiembre de 2013

El Comando seq en UNIX y Linux

Se puede crear una serie de números con el comando seq. Aquí están unos ejemplos. Con un número, seq cuenta desde 1 hasta este número: 

UBUNTU > echo `seq 6`
1 2 3 4 5 6
UBUNTU >

Con dos números, seq cuenta desde el primero hasta el segundo: 

UBUNTU > seq 4 7
4
5
6
7
UBUNTU >

UBUNTU > echo `seq 5 10`
5 6 7 8 9 10
UBUNTU >

UBUNTU > touch file10 file11 file12
UBUNTU > ls
file10  file11  file12
UBUNTU > for x in `seq 10 12`
> do
> rm file$x
> done
UBUNTU > ls
UBUNTU >

Con tres números, seq cuenta desde el primero hasta el tercero. El segundo número precisa la diferencia entre los miembros sucesivos de la serie: 

UBUNTU > echo `seq 10 2.5 20`
10,0 12,5 15,0 17,5 20,0
UBUNTU >