Hi,
I have basic knowledge on unix shell scripting(not an expert).
My requirement is reading the csv file using the schema defined in the configuration file and if the condition is not mached then move the unmatched record to a error file and matched good records into other file.
In brief:
Here i'm defining the schema of an input file in normal text file and I'm calling it as configuration file. My configuration file looks like :
col1 integer NN
col2 string
col3 string NN
Also I'm having a data file ( say its a .csv file) and it looks like :
id,name,location
1,John,FL
2,Merry,,
3,Taylor,CA
a,George,MI
So here i need to write unix sript such a way that while reading the csv data file ,it should refer to the configuration file for the datatype and whether that field is NULL or not. If it is not satisfying the condition it should drop that whole record and move for the next row for the validation check.
Here it has to read the 1st row value from the csv file and check the datatype of that value from the configuration file. If the value type of the 1st row is matched with the datatype of the 1st column , then it has to move the matched record into a new file and if unmatched record is found it has to move those error records into an error file.
How this can be done using UNIX shell scripting.
Here my expected result is :
id,name,age
1,John,FL
3,Taylor,CA
Rest of the records are dropped because :
2,Merry,, ---> here 3rd filed is NULL but in configuration file it is NOT NULL(NN)
a,George,MI --> here 1st field value is STRING where in conf file it is INTEGER.
So how this could be achieved in unix script and what are the commands need to be used to do this.
Please let me know if the scenario is not clear.
Thanks,
Shree11