I have this task of uploading a delimited file and processing it. Once the processing is done, I either say its successful and if parsing fails, I need to throw the error. I'm reading this file line by line in child script and then processing it in main script (so I can't use ifs while read).
I'm renaming to .done in case all lines are parsed. Now I would like to know when there is an error before EOF has reached so that I can rename it to .err. And what if I have a file without newline character at the end?
Structure is mostly as below:
Main script:
Calls parent script with filepath
gets the fileName and no of line in the files, calls the Child script with a nth line no in a loop until total no of lines are reached
Parent script:
#some validations to get the txt file from the list of files
...
fileName=`ls -A1 *.txt`
...
Child script:
...
lineno=$1
fileName=$2
noOfLines=$3
line=`tail -$lineno $fileName | head -n1`
if [ $lineno -eq $noOfLines ]
then
noExt="${fileName%.*}"
mv "$fileName" "$noExt.done" #success case
fi
Now I also need to rename the file to .err if its erroneous or parsing fails. How do I catch the error?