CalmSoul
asked on
python export content to text file
I have following files with extension (*.olu) (i.e. really mean txt file) in one directory. More than 1 million.
-Read anything within [] and make it column in text file - shown in example below (element-type) value of that column is after = sign (for example: OU Document with type in example provided)
I am looking for python to parse through each *.olu file in the directory and export following information out in text file (pipe delimited)
-Read anything within [] and make it column in text file - shown in example below (element-type) value of that column is after = sign (for example: OU Document with type in example provided)
[element]
Type=OU Document with type
[Docs]
1=\ft\ou\ds\comb\5623589556536.TIF
2=\ft\ou\ds\comb\5623589556586.TIF
[Indices.1]
account_number=9999999
first_name=test user
address=0
sub_class=OUT
linux_date=20000630
bentch_date= / /
mod_acct_num=
[Indices.2]
account_number=9999999
first_name=test user
address=0
sub_class=OUT
linux_date=20000630
bentch_date= / /
mod_acct_num=222
I am looking for python to parse through each *.olu file in the directory and export following information out in text file (pipe delimited)
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
| Filename | element-type | Docs.1 | Docs.2 | Indices.1-account_number | Indices.1-first_name | Indices.1-address | Indices.1-sub_class | Indices.1-linux_date | Indices.1-bentch_date | Indices.2-mod_acct_num | *** |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
| *.olu | OU Document with type | \ft\ou\ds\comb\5623589556536.TIF | \ft\ou\ds\comb\5623589556586.TIF |9999999 | test user | 0 | OUT | 20000630 | / / | | |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
| | | | | | | | | | | | |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
| | | | | | | | | | | | |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
ASKER
thanks pepr - let me test this ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is the code that gets the info from the file (read the comments):
Open in new window
The code gets the attributes in the order they are used in the file. It will be better to use the list of attribute names that you need and process them in the given order Also, the list can be used to create a header, if you really need it.
It is a question why you would need that pretty formatting. But if you want it, it is possible. The alternative could be to use the csv standard module to output the rows to the csv file.
The code prints the following for your example:
Open in new window