Anotações Linux shell script
.
AnotacoesLinuxShellScript.txt
.
Não quero de forma alguma aprender tudo hoje nem amanhã. Saber tudo é horrível. Rouba de mim o prazer de estudar. Não saber é bom, pois assim, posso buscar e aprender alguma coisa. Qualquer coisa. Creio que uma pessoa que sabe tudo, no final, talvez não possa fazer nada.
.
CRIAR DIRETORIO/PASTA
.
mkdir -p ~/Downloads/NotasLinuxShell/EstLinux
.
NAVEGAR ATÉ EstLinux
.
cd ~/Downloads/NotasLinuxShell/EstLinux
pwd
.
OBJETIVO CONTAR PALAVRAS EM SHELL
.
criar um arquivo de texto com dezoito palavras em seis linhas
.
echo -e 'contando palavras shell \nFalantes loa leia \nLuz olhos shell \nCibernético planos sonda \nEscritor não loucura \nCharles Aluno1 leia' > ContarPalavrasEmShell.txt
.
EXECUTANDO COMAND WC DO PACOTE GNU COREUTILS
.
1) wc -w ContarPalavrasEmShell.txt
2) wc -w /etc/passwd
3) wc -l ContarPalavrasEmShell.txt
4) wc -l /etc/passwd
5) wc -c ContarPalavrasEmShell.txt
6) wc -c /etc/passwd
7) wc -m ContarPalavrasEmShell.txt
8) wc -m /etc/passwd
.
Se executar "echo 333 | wc -c" o resultado é 4
.
EXECUTO:
.
echo 333 | wc -c
.
ME INFORMANDO SOBRE O COMANDO UNIQ NA MANPAGE:
.
man uniq | grep count
.
man uniq | grep -A 1 count
.
man uniq | grep -A 3 count
.
man uniq | grep -A 5 count
.
EXECUTO:
echo ; cat ContarPalavrasEmShell.txt | uniq -c ; echo
.
O RESULTADO NÃO É BEM O CORRETO
.
EXECUTO:
echo ; cat ContarPalavrasEmShell.txt | sort | uniq -c ; echo
.
clear ; echo ; cat ContarPalavrasEmShell.txt | sort #| uniq -c ; echo
.
TEM QUE SER UMA PALAVRA POR LINHA LINHA E ESTAS LINHAS DEVEM ESTAR ORDENADAS.
.
CRIO NOVO ARQUIVO DE TEXTO
.
EXECUTO:
echo -e 'leia1\nleia2\nleia3\nleia4\nleia5' > LeiaPalavrasEmShell.txt
.
EXECUTO:
.
cat LeiaPalavrasEmShell.txt | sort | uniq -c
.
cat LeiaPalavrasEmShell.txt | sort #| uniq -c
.
COPIO ESTE TEXTO DA INTERNET:
.
Se vai tentar
siga em frente.
Senão, nem começe!
Isso pode significar perder namoradas
esposas, família, trabalho...e talvez a cabeça.
Pode significar ficar sem comer por dias,
Pode significar congelar em um parque,
Pode significar cadeia,
Pode significar caçoadas, desolação...
A desolação é o presente
O resto é uma prova de sua paciência,
do quanto realmente quis fazer
E farei, apesar do menosprezo
E será melhor que qualquer coisa que possa imaginar.
Se vai tentar,
Vá em frente.
Não há outro sentimento como este
Ficará sozinho com os Deuses
E as noites serão quentes
Levará a vida com um sorriso perfeito
É a única coisa que vale a pena.
-- Charles Bukowski
.
EXECUTO:
.
vi PoesiaBukowski.txt
.
Aperto Esc. digito i. colo o texto copiado com o mouse. confiro. Aperto Esc. Digito :wq.
.
EXECUTO:
ls -tli
.
clear
cat | uniq -c PoesiaBukowski.txt
.
OBS:
teclo Ctrl C
.
MAS QUERO CONTAR UMA PALAVRA POR LINHA
.
EXECUTO:
cat PoesiaBukowski.txt | sort | uniq -c
.
PARA UMA PALAVRA POR LINHA USO "xargs -n 1"
.
EXECUTO:
1)
cat PoesiaBukowski.txt | xargs -n 1
2)
clear ; echo ; cat PoesiaBukowski.txt | xargs -n 1 ; echo
3)
cat PoesiaBukowski.txt | xargs -n 3
4)
clear ; echo ; cat PoesiaBukowski.txt | xargs -n 3 ; echo
5)
cat PoesiaBukowski.txt | xargs -n 4
6)
clear ; echo ; cat PoesiaBukowski.txt | xargs -n 4 ; echo
.
SEM VIRGULAS E PONTOS
.
EXECUTO:
cat PoesiaBukowski.txt | egrep -o '\w+'
.
PARA ORDENAR E PARA CONTAR
.
EXECUTO:
clear
cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c
.
ORDENAR OS QUE MAIS APARECEM
.
EXECUTO:
clear
cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c | sort -n
.
ISTO É ÚTIL SE EU ESCREVO UM TEXTO E TENHO VÍCIO DE USAR CERTAS PALAVRAS EM EXCESSO, ACHO EU; QUE ESCREVO.
.
MOSTRAR DO MAIOR PARA O MENOR
.
EXECUTO:
clear
cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c | sort -n -r
.
PARA VER SÓ AS DEZ PRIMEIRAS
.
EXECUTO:
clear
cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c | sort -n -r | head
.
PARA VER A QUE MAIS APARECE NO TEXTO:
.
EXECUTO:
cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c | sort -n -r | head -n1
.
PARA VER AS 7 QUE MAIS APARECEM
.
EXECUTO:
1) clear
2) cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c | sort -n -r | head -n 7
3) echo ; cat PoesiaBukowski.txt | egrep -o '\w+' | sort | uniq -c | sort -n -r | head -n 7 ; echo
4) egrep -o '\w+' (uma palavra por linha), sort (ordena), uniq -c (conta), sort -n -r (o resultado é ordenado numericamente do maior para o menor), head -n 7 (pega as sete primeiras)
.
Me pergunto se num desafio, alguém poderia produzir um texto poderoso como o que achei na internet usando as sete palavras mais usadas na poesia:
.
5 significar
4 Pode
4 a
3 que
3 em
3 E
2 vai
.
QUERO SÓ AS QUE TIVEREM TRES LETRAS OU MAIS.
.
EXECUTO:
1)
cat PoesiaBukowski.txt | egrep -o '\w+' | grep ...
2)
cat PoesiaBukowski.txt | egrep -o '\w+' | grep .....
3)
cat PoesiaBukowski.txt | egrep -o '\w+' | grep ... | sort | uniq -c | sort -n -r | head -n 7
4)
clear ; echo ; cat PoesiaBukowski.txt | egrep -o '\w+' | grep ... | sort | uniq -c | sort -n -r | head -n 7 ; echo
5)
cat PoesiaBukowski.txt # | egrep -o '\w+' | grep ... | sort | uniq -c | sort -n -r | head -n 7
6)
cat PoesiaBukowski.txt | egrep -o '\w+' # | grep ... | sort | uniq -c | sort -n -r | head -n 7
.
E assim usando Linux disseco uma poesia.
.
Até Breve
.