I get file whith a variable number of semicolons to separate my data. 8 mandatory columns with 7 semicolons to separate 2 non mandatory columns (linked, both exist or not), if exist, 9 semicolons in the file (what i need).
My asking is test all lines in file, test if 7 semicolons then add 2 semicolons at the end. If 9 semicolons then do nothing.
07/15/19 02:58:40 PM;toto2_UBD_FD_GPRS_GLBL_EXCP;TABLE;DATA;COMPLETE;BASE_TEST_DSA;0;0
07/15/19 02:58:40 PM;toto_UBD_FD_GPRS_GLBL_EXCP;TABLE;DATA;COMPLETE;BASE_TEST_DSA;37484032;253118
07/15/19 02:55:59 PM;UBD_FD_GPRS_GLBL_EXCP;TABLE;DATA;COMPLETE;BASE_TEST_DSA;37484032;253118
07/15/19 02:55:59 PM;UBV_FD_GSM_GLBL_EXCP;TABLE;DATA;COMPLETE;BASE_TEST_DSA;0;0
07/15/19 02:55:59 PM;UBV_FD_GSM_GLBL_EXCP;TABLE;DATA;COMPLETE;BASE_TEST_DSA;0;0;E1234;LIB1234
I imagine something like :
while read line; do
if [[ `awk -F ";" ' { print NF-1 }'` = "7" ]]; then
sed '/;$/!s/$/;;/' $line
fi
done < TEST_FILE2.txt > TEST_FILE3.txt
Aucun commentaire:
Enregistrer un commentaire