DebbieFost
asked on
Require a script to find and replace values in a CSV file those from a TXT file
I have a CSV file that contains two fields per row, and the first field MAY contain a a value that needs to be replaced with a number from a translation table CSV).
i.e.
C:\INPUT.CSV contains the following:
1233456,09/06/13 - 21:24 - Note to file - John Smith
89012345,09/06/13 - 21:24 - TItle - Jackson Jones
ZMOD91010,09/06/13 - 21:24 - Notices - Greg Whote
ABC223020,09/06/13 - 21:24 - Summary - Frank Bray
C:\Translation.CSV contains the following:
123938108,2093420348
2938108310,10293931
213912391,12301384
91010,109201
223020,1353453
I need a script to do the following:
1. Where Field1 in C:\Input.csv contains any prefixed alpha characters, remove them from the field to leave the number only in FIELD1
2. Where any FIELD1 value in C:\Input.csv contains a number that is in Field1 of Translation.CSV, replace that value with the referenced value in FIELD2 of Translation.CSV
The output will then be written to C:\Output.CSV (using the above examples):
1233456,09/06/13 - 21:24 - Note to file - John Smith
89012345,09/06/13 - 21:24 - TItle - Jackson Jones
109201,09/06/13 - 21:24 - Notices - Greg Whote
1353453,09/06/13 - 21:24 - Summary - Frank Bray
Input.csv
Transplation.csv
i.e.
C:\INPUT.CSV contains the following:
1233456,09/06/13 - 21:24 - Note to file - John Smith
89012345,09/06/13 - 21:24 - TItle - Jackson Jones
ZMOD91010,09/06/13 - 21:24 - Notices - Greg Whote
ABC223020,09/06/13 - 21:24 - Summary - Frank Bray
C:\Translation.CSV contains the following:
123938108,2093420348
2938108310,10293931
213912391,12301384
91010,109201
223020,1353453
I need a script to do the following:
1. Where Field1 in C:\Input.csv contains any prefixed alpha characters, remove them from the field to leave the number only in FIELD1
2. Where any FIELD1 value in C:\Input.csv contains a number that is in Field1 of Translation.CSV, replace that value with the referenced value in FIELD2 of Translation.CSV
The output will then be written to C:\Output.CSV (using the above examples):
1233456,09/06/13 - 21:24 - Note to file - John Smith
89012345,09/06/13 - 21:24 - TItle - Jackson Jones
109201,09/06/13 - 21:24 - Notices - Greg Whote
1353453,09/06/13 - 21:24 - Summary - Frank Bray
Input.csv
Transplation.csv
ASKER
That is awesome Bill - initial testing looks great. Is it possible to code it so it will CREATE a new file called OutPut.CSV? The environment this is in will always move the Output.CSV file out of the folder, so there will not be an existing file to write to.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
cscript EE28248438.vbs control.txt in.txt out.txt
Where control.txt is the name of your translation file, and then the names of the input and output files follow that.
Open in new window
~bp