Zusammenfassung der Ressource
103.2 Process text
streams using filters
- Send text files and output streams through
text utility filters to modify the output using
standard UNIX commands found in the GNU
textutils package.
- bzcat
cat
cut
head
less
md5sum
nl
od
paste
sed
sha256sum
sha512sum
sort
split
tail
tr
uniq
wc
xzcat
zcat
- Comando cat
- Type Cat Enter
and random
text
- cat >
mytextfile (Graba)
- Hola Bienvenidos al Cumpleaños en Casa
es un placer poder compartir con
ustedes^C
- cat mytextfile
(Visualiza)
- Hola Bienvenidos al
Cumpleaños en Casa es un
placer poder compartir
con ustedes^
- cat mytextfile >
mynewtextfile
- cat to direct its
output to the
mytextfile file
- diff mynewtextfile mytextfile
- You can actually verify that
these two files have the same
content by performing a diff
- echo 'This is my new line' >> mynewtextfile
- diff mynewtextfile mytextfile
- 4d3 < This is my new
line
- cat mytextfile | grep this
- cat mytextfile | grep -i this
- Processing Text Streams
- vi ftu.txt
- bzcat cat
cut head
less
md5sum nl
od paste
sed
sha256sum
sha512sum
sort split
tail tr uniq
wc xzcat
zcat
- cat ftu.txt | grep cat
- bzcat
cat
xzcat
zcat
- grep cat ftu.txt
- bzcat
cat
xzcat
zcat
- commands that handle
compressed files
- bzcat
- bzip
compresed
files
- xzcat
- xz
compresed
Files
- gzip
- gzip
compresed
files
- gzip ftu.txt
- ftu.txt.gz
- comprimir
- zcat ftu.txt.gz
- Visualizar
- Viewing a File in a Pager
- sudo cat /var/log/syslog
- sudo less /var/log/syslog
- sudo head /var/log/syslog
- sudo tail /var/log/syslog
- sudo tail -n 5 /var/log/syslog
- sudo head /var/log/syslog | nl
- sudo tail /var/log/syslog | wc -l
- The Basics of sed,
the Stream Editor
- zcat ftu.txt.gz | grep -v cat
- gunzip ftu.txt.gz
- sed -n /cat/p < ftu.txt
- listar solo las líneas que
contienen la cadena cat
- <
- redirige ftu a sed
- /cat/
- string to search
- -n
- La opción -n instruye a sed
para que no produzca
salida (a menos por las
instrucciones posteriores
del comando p)
- sed /cat/d < ftu.txt
- cut
head
less
md5sum
nl
od
paste
sed
sha256sum
sha512sum
sort
split
tail
tr
uniq
wc
- sed s/cat/dog/ < ftu.txt
- Change cat by dog
- sed -i.backup s/cat/dog/ ftu.txt
- Insertar
- Ensuring Data Integrity
- los archivos de imagen del instalador de
Debian están acompañados por archivos
de texto que contienen sumas de
verificación de los archivos de los
diversos algoritmos (MD5, SHA1, SHA256 y
SHA512).
- [SUM] SHA512SUMS [CRT]
SHA512SUMS.sign
[ISO]debian-10.1.0-amd64-netinst.iso
- sha256sum ftu.txt
- 45452304fc26999a715652543c352e5fc7ee0c1b9deac6f57542ec91daf261c ftu.txt
- sha256sum ftu.txt > sha256.txt
- sha256sum -c
sha256.txt ftu.txt:
OK
- echo "new entry" >> ftu.txt
- la suma no
coincide
- Looking Deeper into Files
- od
- od ftu.txt
- 0000000 075142 060543 005164 060543
005164 072543 005164 062550 0000020
062141
- octal
- od -x ftu.txt
- Hexadecimal
- od -c ftu.txt
- Caracteres
- od -An -c ftu.txt
- delete desplazamiento de bytes
- se usa para depurar
aplicaciones y varios
archivos
- Preguntas y
Respuestas
- 1.- Usando los comandos sed, grep y wc muestre cuántos
procesadores tiene.
- sed -n /processor/p /proc/cpuinfo | wc -l
- grep processor /proc/cpuinfo | wc -l
- 2.- Explorar /etc/passwd
- 1.- ¿¿Qué usuarios tienen
acceso a un shell Bash??
- grep /bin/bash /etc/passwd
- grep ":/bin/bash$" /etc/passwd | cut -d: -f1
- 2.- ¿Cuántos usuarios no
tienen acceso al shell?
- grep /bin/false /etc/passwd
- 3.- Cuántos usuarios y
grupos existen en su
sistema (recuerde: use solo
el archivo /etc/passwd)?
- a.- cut -d: -f3 /etc/passwd | wc -l
- b.- cut -d: -f3 /etc/passwd |sort -u | wc -l
- 4.- Muestre solo la primera línea, la
última línea y la décima línea de su
archivo /etc/passwd.
- sed -n -e '1'p -e '10'p -e '$'p /etc/passwd
- Recuerde que el parámetro -n le dice a sed que
no imprima nada más que lo especificado por el
comando p. El signo de dólar ($) usado aquí es
una expresión regular que significa la última
línea del archivo.
- 5.- Liste todos los
usuarios en el grupo
1000
- sed -n /:1000:[A-Z]/p /etc/passwd
- 6.- Enumere solo los nombres
completos de todos los
usuarios de este grupo (use
sed y cut):
- sed -n /:1000:[A-Z]/p mypasswd | cut -d: -f5
- sed -n /:1000:[A-Z]/p mypasswd | cut -d: -f5 | cut -d, -f1
- 7.- utilizando el archivo mypasswd de los ejercicios
anteriores, idee un comando Bash que seleccionará
a una persona de la Oficina Principal para ganar un
concurso de rifas.
- sed -n /Main\ Office/p mypasswd | cut -d: -f5 | cut -d, -f1 | sort -R | head -1
- 8.- ¿Cuántas personas trabajan en
Recursos Humanos, Ingeniería y
Cuentas por pagar?
- sed -n /Main\ Office/p mypasswd | cut -d: -f5 | cut -d, -f2 | uniq -c
- -c
- Cuenta las ocurrencias
- ¿9.- Preparar el sigueinte archivo El contenido del archivo
tendrá el siguiente formato:?
- sed -n /Main Office/p mypasswd | cut -d: -f5 | cut -d" " -f1 > firstname
- sed -n /Main Office/p mypasswd | cut -d: -f5 | cut -d" " -f2 | cut -d, -f1 > lastname
- ¿10.- Departamento en que
trabaja cada empleado?
- sed -n /Main Office/p mypasswd | cut -d: -f5 | cut -d, -f2 > department
- 11.- ¿Solucion Final ?
- cat firstname lastname department
- paste firstname lastname department
- paste  firstname lastname department | tr '\t > names.csv
- paste -d, firstname lastname department
- sed -n /Main Office/p mypasswd | cut -d: -f5 | cut -d, -f1,2 | tr ' ' , > names2.csv
- Preguntas y Respuestas
- 1.- ¿Cómo podemos asegurar la integridad del archivo names.csv usando md5sum?
- md5sum names.csv
- b42d753fe22b94bd3915272f127acf4c names.csv
- message digest
- sha256sum names.csv
- b04766220f36d0cce33afe23fa41f53c6eb685646d2a9e1f7d5fe9aed740b950 names2.csv
- message digest
- 2.- Si el archivo se ha modificado
ligeramente, el resumen del mensaje será
completamente diferente. Solo para
demostrarlo, edite names.csv y cambie
James a Jones como se muestra aquí:
- sed -i.backup s/James/Jones/ names.csv
- md5sum names.csv
- f44a0d68cb480466099021bf6d6d2e65 names.csv
- message digest
- 3.- ¿Como dividir un archivo de varias lineas en pedazos de 100 lineas?
- download the file
- wget https://www.gutenberg.org/files/50461/50461-0.txt
- how many have line
- cat 50461-0.txt |wc -l
- dividir en trozos de 100 lineas
- split -l 100 -d 50461-0.txt melville
- melville00
.......
melvillenn
- melville
es el
prefijo
- -l 100 numero de
lineas
- -d 50461-0.txt
- Numere los archivos
usando l prefijo
melville
- Trabajando con la salida del comando ls en /etc
- ls -l /etc | tr -s ' ' ,
- -s: suprime multiples espacios en banco en la saida
- ls -l /etc | tr -s ' '
- ls -l /etc | tr -s ' ' | cut -d" " -f9
- Nombre archivo
- ls -l /etc | tr -s ' ' | cut -d" " -f9,3
- nombre de archivo y dueño
- $ ls -l /etc | grep ^d | tr -s ' ' | cut -d" " -f9,3
- Nombres de carpetas y dueño
- tail -f /var/log/syslog | grep -i 'product\:\|blocks\|manufacturer'
- SEguirle la pista a message con tail