Excluir alguns arquivos
Se o nome do arquivo contiver "PO_Consumption_", ele será excluído.
for f in *.csv; do
if [ $(echo "$f" | grep -c PO_Consumption_) -gt 0 ]; then
rm "$f"
fi
done
Se o arquivo gz estiver corrompido, ele será excluído.
# Cuidado, se os arquivos forem gz.gz eles serão excluídos
for f in *.gz; do
if [ -f "$f" ]; then
gunzip "$f"
if [ $? -eq 0 ]; then
echo "arquivo OK"
else
echo "arquivo não OK"
rm "$f"
fi
fi
done
Excluir linhas de um arquivo antes de uma palavra específica
- Aqui excluímos linhas antes que a palavra "Schichttext" apareça (a linha com a palavra será mantida)
for f in *.txt; do
if [ $(echo $f | grep -c pm2_sh) -gt 0 ]; then
if [ $(egrep -a -h "Schichttext" "$f" | wc -l) -gt 0 ]; then
new_file2=text_"$f"
cp $f "$new_file2"
sed -n -i '/Schichttext/,$p' "$new_file2"
mv $new_file2 "$PathRepo"
fi
mv $f "$PathRepo"
fi
done