How to extract data from txt files and write into another txt file in a predefined format


Example
1- Read data between "|-" and "-|"
xxxxxxx|-product a-|xxxxxxxx|- prodcut b-|xxxxx|- product c -| xxxxxx |- product d -|

2- And now write in txt file in a format defined below
product a | prodcut b | product c |

Can anyone provide me source code for this. This will help me alot.
Looking for a positive answer.