Linux shell script usando egrep
---
Neste teste crio um diretório e dentro dele um arquivo com strings para o script
Realizar a busca. Executo os comandos abaixo:
1) mkdir -pv ~/TESTES/TESTES_grep/
2) cd ~/TESTES/TESTES_grep/
3) touch texto_testes_grep_egrep.txt
4) echo -e "caminho\nCaminho \ncaminhos \nLuz \nluz \nSol \nsolar\nTempo\nvirus\n" > texto_testes_grep_egrep.txt
5) cat texto_testes_grep_egrep.txt
---
Crio bash shell script em um arquivo de texto no diretório TESTES_grep/ (dou permissão de execução chmod +x ) este bash shell script abaixo:
#!/usr/bin/env bash
# titulo: egrep_script_test_1.sh
# autor:
# email:
# site:
# data: 28-03-2020_10:09:59
# distro:
# exemplo de uso: . ./egrep_script_test_1.sh
# objetivo:
# variaveis:
# TODO - indica uma tarefa a ser feita
# FIXME - indica um bug conhecido que precisa ser arrumado
# XXX - Notícia, chama a atenção
echo -e "\n\e[1;32mVou buscar uma string em algum arquivo.\e[0m\n"
read -p "Digite o termo de busca: " busca
echo -e "\n\e[1;32mVocê digitou $busca\e[0m\n"
# -------------------- #
read -p "Digite o caminho/nome do arquivo: " arquivo
echo -e "\n\e[1;32mVocê digitou $arquivo\e[0m\n"
read -p "tecle Enter para iniciar a busca: "
egrep -i "$busca" "$arquivo"
# fim do script
---
Agora vou testar o script criado.
---
~/TESTES/TESTES_grep:$ ls -CF
egrep_script_test_1.sh* texto_testes_grep_egrep.txt
~/TESTES/TESTES_grep:$ . ./egrep_script_test_1.sh
Vou buscar uma string em algum arquivo.
Digite o termo de busca: caminho
Você digitou caminho
Digite o caminho/nome do arquivo: texto_testes_grep_egrep.txt
Você digitou texto_testes_grep_egrep.txt
tecle Enter para iniciar a busca:
caminho
Caminho
caminhos
~/TESTES/TESTES_grep:$
---