|
From: | dicipolo_rafael |
Subject: | Re: [shell-script] Obter quantidade de coluna no while. |
Date: | 26 Jul 2016 09:00:01 -0700 |
while read line; do
CAMPO1=`echo $line |awk -F"|" '{print $1}'`
CAMPO2=`echo $line |awk -F"|" '{print $2}'`
CAMPO3=`echo $line |awk -F"|" '{print $3}'`
NCOLUNA=`echo $line |awk -F"|" '{print NF }'`
if [ -z "$CAMPO1" ]; then
echo "CAMPO1 - OBRIGATORIO - $CAMPO1" >> error.log
elif [ -z "$CAMPO2" ]; then
echo "CAMPO2 - OBRIGATORIO - $CAMPO1" >> error.log
elif [ -z "$CAMPO3" ]; then
echo "CAMPO3 - OBRIGATORIO - $ID_CURSO" >> error.log
elif [ "$NCOLUNA" -ne "8" ]; then
echo "NUMERO DE COLUNA FORA DO PADRAO - $ID_CURSO" >> error.log
else
echo "$CAMPO1 CAMPO2 CAMPO3" >> arquivo.sql
done < arquivo
Peguei a saída que você mandou " <(awk -F '|' 'NR==8' arquivo)" alterei para <(awk -F '|' 'NR=8' arquivo) e funcionou perfeitamente inserindo apenas as linhas com 8 coluna. porém queria conseguir gerar o log da linha que não foi inserido por não estar dentro da condição de 8 colunas. consigo fazer essa validação ainda neste mesmo while? se não irei apelar para dois while um fazendo só a condicional de linha fora do padrão rs.
Mais uma fez Obrigado pela ajuda.
[Prev in Thread] | Current Thread | [Next in Thread] |