Solved i need a script to drop some fields in a bat file as i copy

February 9, 2017 at 01:27:06
Specs: Windows 7
i have this file i need to move from one server to another but while copying or moving it drop some fields in each line item of the file. i have over 1000 line items but all similar. i want to export the file and delete/drop the highlighted fields/values/characters.

20160424T155900.000Z,40.893594,TAN.U4.GENE.AICO.OUTWATER_FLOW
20160424T155930.000Z,41.80125,TAN.U4.GENE.AICO.OUTWATER_FLOW
20160424T160000.000Z,41.80125,TAN.U4.GENE.AICO.OUTWATER_FLOW

i intend to drop the 20, T, and 000Z to remain with

160424155900.40.893594,TAN.U4.GENE.AICO.OUTWATER_FLOW
160424155930.41.80125,TAN.U4.GENE.AICO.OUTWATER_FLOW
160424160000. 41.80125,TAN.U4.GENE.AICO.OUTWATER_FLOW


See More: i need a script to drop some fields in a bat file as i copy

Report •

#1
February 9, 2017 at 07:32:23
✔ Best Answer
Here you go

change file.txt on line 2 to your file's name, or rename your file to file.txt

::start of test.bat

@echo off&setlocal EnableDelayedExpansion&pushd %~dp0
set "file=file.txt"
for /f %%a in (!file!) do set "string=%%a"&echo !string:~2,6!!string:~9!>>new-!file!.txt
for /f "tokens=1-10 delims=.," %%a in (new-!file!.txt) do echo %%a,%%c.%%d.%%e.%%f.%%g.%%h.%%i>>new-new-!file!.txt
del new-!file!.txt

::end of test.bat

new-new-file.txt:

160424155900,40.893594.TAN.U4.GENE.AICO.OUTWATER_FLOW
160424155930,41.80125.TAN.U4.GENE.AICO.OUTWATER_FLOW
160424160000,41.80125.TAN.U4.GENE.AICO.OUTWATER_FLOW

Simple solutions are often the best

message edited by hidde663


Report •

#2
February 10, 2017 at 01:33:39
Wow!!

Works like magic. Thanks for the solution. However i realise that i dont want to rename the file since i want to maintain the original File name when its copied to the new server location. How can i maintain the original file names??


Report •

#3
February 10, 2017 at 04:46:21
I'll do that in a few hours, got a driving lesson in 10min.

I could make it a drag and drop tool if you'd like.

How many files are we talking about btw?
Or is it just the one?

Since i could also make it to do all the files in the directory(folder)

I'll also make it so it will rename the new-new-!file! to the original name, then delete the old file. But since the next version wont be fully tested I suggest you make a backup of the files :D.

Simple solutions are often the best

message edited by hidde663


Report •

Related Solutions

#4
February 10, 2017 at 05:11:19
That shall be fine. The system copies one file after every 30mins from one site to another. each file has about 1000line items for example:

20160424T155900.000Z,40.893594,TAN.U4.GENE.AICO.OUTWATER_FLOW
20160424T155930.000Z,41.80125,TAN.U4.GENE.AICO.OUTWATER_FLOW
20160424T160000.000Z,41.80125,TAN.U4.GENE.AICO.OUTWATER_FLOW
.
.
.
.
n.

All the best in your driving lessons.


Report •

#5
February 10, 2017 at 16:33:00
Thanks :D

Make sure to make a backup for the first try...

Here is the drag and drop version:

::start of convert.bat

@echo off&setlocal EnableDelayedExpansion&pushd %~dp0
if '%~nx1'=='' echo ERROR: No file dropped in&pause>nul&exit /b
set "file=%~nx1"
for /f %%a in (!file!) do set "string=%%a"&echo !string:~2,6!!string:~9!>>"new-!file!"
for /f "tokens=1-10 delims=.," %%a in (new-!file!) do echo %%a,%%c.%%d.%%e.%%f.%%g.%%h.%%i>>"new-new-!file!"
del "!file!" "new-!file!"
ren "new-new-!file!" "!file!"

::end of convert.bat

Simple solutions are often the best


Report •

#6
February 13, 2017 at 21:14:19
Helloo..

ran the script and it has given me exactly what i was looking for.
Thanks a bunch for the help wit this. i appreciate.

Peace out Bro.


Report •

Ask Question