Conditional Concatenation Of Records In A File
Posted: 07 Feb 2017 16:33
Hi All,
I am trying to write a batch script which will conditionally concatenate the records in the file, I was able to find few batch scripts online but the batch programs are concatenation all the records.
Can any one suggest me some logic on how to achieve the below.
I have a directory with a list of .txt files, each file will have data as below. I am trying to join the record with starts with 3 with the previous record which starts with 2.
Sample data pasted below.
Source files data
Expected Output
I am trying to write a batch script which will conditionally concatenate the records in the file, I was able to find few batch scripts online but the batch programs are concatenation all the records.
Can any one suggest me some logic on how to achieve the below.
I have a directory with a list of .txt files, each file will have data as below. I am trying to join the record with starts with 3 with the previous record which starts with 2.
Sample data pasted below.
Source files data
1|123|
2|Source|T|2016-01-01
3|CDR|XYZ|||||||||||||
3|CDR|XYZ|||||||||||||
4|||||||
2|Source|T1|2016-02-01
3|CDR1|XYZ1|||||||||||||
3|CDR2|XYZ2|||||||||||||
3|CDR1|abc1|||||||||||||
3|CDR2|abc2|||||||||||||
4|||||||
2|Source|T2|2016-03-01
3|CDR3|XYZ3|||||||||||||
3|CDR4|XYZ4|||||||||||||
4|||||||
5||||||||
Expected Output
1|123|
3|CDR|XYZ|||||||||||||2|Source|T|2016-01-01
3|CDR|XYZ|||||||||||||2|Source|T|2016-01-01
4|||||||
3|CDR1|XYZ1|||||||||||||2|Source|T1|2016-02-01
3|CDR2|XYZ2|||||||||||||2|Source|T1|2016-02-01
3|CDR1|abc1|||||||||||||2|Source|T1|2016-02-01
3|CDR2|abc2|||||||||||||2|Source|T1|2016-02-01
4|||||||
3|CDR3|XYZ3|||||||||||||2|Source|T2|2016-03-01
3|CDR4|XYZ4|||||||||||||2|Source|T2|2016-03-01
4|||||||
5||||||||