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 cant use ifs while read).
Im 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. Pls let me know how do i catch the error.