Preciso criar e escrever em um novo arquivo baseado em ocorrências encontradas em outro arquivo. ou seja:
Occurrence found in first file
then write same Occurrence in another one/new
para ser mais específico:
"File1": para encontrar Ocorrências:
Occurrence1
Occurrence2
OccurrenceN
##If the `Occurence1` is find in `File1` then write in the `new file` the same Occurrence
Tenho o próximo comando funcional ksh
para especificar as ocorrências no arquivo e quantas não:
users=(Occurrence1 Occurrence2 Occurrence3 Occurrence4 ... OccurrenceN)
for i in "${users[@]}"
do
grep -qw $i file1 && echo "$i is in the file" || echo "$i is not in the file"
done
Eu faço algumas modificações no código inicial:
users=(Occurrence1 Occurrence2 Occurrence3 ... OccurrenceN)
for i in "${users[@]}"
do
grep -qw $i File1.txt && echo "$i is in the file" || echo "$i is not in the file"
if [[ $user = "*is in the file" ]]; then
echo $user >> users_in_file.txt
elif [[ $user = "*is not in the file" ]]; then
echo $user >> users_not_in_file.txt
fi
done
Tenho ideia de implementar o último comando para pegar meu objetivo, mas não está funcionando. Tem outro para fazer? Desde já, obrigado. Qualquer dúvida poste como comentário.
Você pode usar
grep
diretamente como condição doif
, e proceder de acordo: