Converting IBM DB2 IXF file to CSV or XML
Question:
How do I convert an exported IXF file (using db2 export
) to a human-readable format, like CSV or XML? I am comfortable with doing it in Python or .NET C#.
Answers:
The PC/IXF format is fairly complex, and is practically unknown to programs outside of DB2. Writing your own PC/IXF parser just to convert an IXF file directly to some other format might take a while. A faster alternative is to issue an IMPORT command on the DB2 server and specify CREATE INTO instead of INSERT INTO , which will generate a brand new table that can accommodate the contents of the file being imported. This will allow you to run an EXPORT command on the new table to dump the rows to a delimited format.
In case you still want write your own PC/IXF parser, you can take a look at this project, that converts IXF file to JSON
IXF is an old and also well documented file format. It is possible to read and process it, I’ve done this couple of years ago. So don’t let you be discouraged. It’s hard, but not too hard for developers.
Today you can find also solutions on GitHub, e.g. ixfcvt
You said you are confortable with python. Therefore, you can try this :
pip install db2ixf
You can either use the CLI or the python code.
CLI:
db2ixf csv -s '|' <path/to/your/file.ixf>
-s : Separator (Default is |
)
or:
db2ixf parquet <path/to/your/file.ixf>
or:
db2ixf json <path/to/your/file.ixf>
Python:
from pathlib import Path
from db2ixf import IXFParser
path = Path('path/to/IXF/file.XXX.IXF')
with open(path, mode='rb') as f:
parser = IXFParser(f)
output_path = Path('path/to/output/file.csv')
with open(output_path, mode='w', encoding='utf-8') as output_file:
parser.to_csv(output_file)
If you need more documentation, you can visit this link.
How do I convert an exported IXF file (using db2 export
) to a human-readable format, like CSV or XML? I am comfortable with doing it in Python or .NET C#.
The PC/IXF format is fairly complex, and is practically unknown to programs outside of DB2. Writing your own PC/IXF parser just to convert an IXF file directly to some other format might take a while. A faster alternative is to issue an IMPORT command on the DB2 server and specify CREATE INTO instead of INSERT INTO , which will generate a brand new table that can accommodate the contents of the file being imported. This will allow you to run an EXPORT command on the new table to dump the rows to a delimited format.
In case you still want write your own PC/IXF parser, you can take a look at this project, that converts IXF file to JSON
IXF is an old and also well documented file format. It is possible to read and process it, I’ve done this couple of years ago. So don’t let you be discouraged. It’s hard, but not too hard for developers.
Today you can find also solutions on GitHub, e.g. ixfcvt
You said you are confortable with python. Therefore, you can try this :
pip install db2ixf
You can either use the CLI or the python code.
CLI:
db2ixf csv -s '|' <path/to/your/file.ixf>
-s : Separator (Default is |
)
or:
db2ixf parquet <path/to/your/file.ixf>
or:
db2ixf json <path/to/your/file.ixf>
Python:
from pathlib import Path
from db2ixf import IXFParser
path = Path('path/to/IXF/file.XXX.IXF')
with open(path, mode='rb') as f:
parser = IXFParser(f)
output_path = Path('path/to/output/file.csv')
with open(output_path, mode='w', encoding='utf-8') as output_file:
parser.to_csv(output_file)
If you need more documentation, you can visit this link.