The record that begins with 1 should have the next record to begin with 2 or 3 else reject that record.
The record that begins with 1 should have the next record to begin with 2 and if there are many records starting with 2, consider the first record only.
The rejected records should be captured in a file and the valid records in another file.
The requirement is this needs to be done in unix shell scripting. Please help me out in this.
I have this requirement in ETL DatStage, but I was not able to derive this requirement so trying to split the records and save in a file through unix scripting and then this file will be utlized in datastage. Please help me in unix scripting as I dont have much knowledge on scripting
This code will generate two files: ok and rejected.
awk > ok 'END {
for (i = 0; ++i <= NR;) {
if (i in r && r ~ /^1/ && i + 1 in r && r[i + 1] ~ /^2/) {
print r RS r[i + 1]
delete r; delete r[i + 1]
if (i + 2 in r && r[i + 2] ~ /^3/) {
print r[i + 2]; delete r[i + 2]
}
}
if (i in r ) print r > "rejected"
}
}
{ r[NR] = $0 }' infile