text file reformatting
iwawi
iwawi123 at gmail.com
Sun Oct 31 15:03:28 EDT 2010
I have this fixed width data file (data.txt) which I would like to
reformat. Data is something like this, with hundreds of rows and
columns, every row finishes to END:
PRJ01001 4 00100END
PRJ01002 3 00110END
PRJ01003 3 00120END
PRJ01004 2 00130END
PRJ01005 1 00140END
PRJ01006 1 00150END
PRJ01007 3 00160END
I would like to pick only some columns to a new file and put them to a
certain places (to match previous data) - definition file (def.csv)
could be something like this:
VARIABLE FIELDSTARTS FIELD SIZE NEW PLACE IN NEW DATA FILE
ProjID ; 1 ; 5 ; 1
CaseID ; 6 ; 3 ; 10
UselessV ; 10 ; 1 ;
Zipcode ; 12 ; 5 ; 15
So the new datafile should look like this:
PRJ01 001 00100END
PRJ01 002 00110END
PRJ01 003 00120END
PRJ01 004 00130END
PRJ01 005 00140END
PRJ01 006 00150END
PRJ01 007 00160END
If the datafile was as narrow as in this demofile, I would simply use
notepad to fix this, but there are more
than 100 variables I should pick and replace...
I'm missing the logic here - how it should be done?
More information about the Python-list
mailing list