sparker1970
asked on
Modify Text File with Batch Script to Create Additional Files Based on Specific Text String in File
I have a text file where I have a defined set of variables that appear in a fixed position in each text record.
The original file location and output location will always be a fixed location: N:\DownloadedFiles\
The data I am evaluating is in positions 18-23 of each row.
If positions 18-23 contain VA8, copy row into a new text file with the following naming convention: VA8_MI186_yyyymmddhhmm.txt (hhmm in military time)
If positions 18-23 contain OH252, copy row into a new text file with the following naming convention: MI186_UPD_OH252_yyyymmdd.t xt
If positions 18-23 contain MI3, copy row into a new text file with the following naming convention: MI186_UPD_MI3_yyyymmdd.txt
The original file location and output location will always be a fixed location: N:\DownloadedFiles\
The data I am evaluating is in positions 18-23 of each row.
If positions 18-23 contain VA8, copy row into a new text file with the following naming convention: VA8_MI186_yyyymmddhhmm.txt
If positions 18-23 contain OH252, copy row into a new text file with the following naming convention: MI186_UPD_OH252_yyyymmdd.t
If positions 18-23 contain MI3, copy row into a new text file with the following naming convention: MI186_UPD_MI3_yyyymmdd.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
... and a PowerShell one, with a slightly different algorithm:
set-location N:\DownloadedFiles\
$data = get-content HelperFile.txt
$data | ? { $_.Substring(17,5) -eq ' VA8' } | out-file "VA8_MI186_$( get-date -format 'yyyyMMddhhmm').txt"
$data | ? { $_.Substring(17,5) -eq 'OH252' } | out-file "MI186_UPD_OH252_$(get-date -format 'yyyyMMdd' ).txt"
$data | ? { $_.Substring(17,5) -eq ' MI3' } | out-file "MI186_UPD_MI3_$( get-date -format 'yyyyMMdd' ).txt"
ASKER
This worked perfectly. Sorry for taking so long to respond. I was out of the office for a few weeks and just getting caught up on everything. I was trying to stick with a basic text/batch file so I did not test the PowerShell solution but some time in the future I may as I just picked up the Windows PowerShell Cookbook...to read in my spare time lol.
Thanks again, worked 100%!
Thanks again, worked 100%!
ASKER
HelperFile.txt