Use .bat to edit a txt file

August 8, 2012 at 13:07:09
Specs: Windows 7
I have been manually editing a txt file on a biweekly basis.
Can this edit be done using a .bat file?

Notepad to open c:\myfile.txt (file always created in same location with same name)
Look for row that starts with '52'
Delete Column 41 (move everything after this left)
Insert Space in Column 50 (move everything after this left)

Look for row that starts with '82'
Delete Column 45 (move everything after this left)
Insert Space in Column 54 (move everything after this left)

close


See More: Use .bat to edit a txt file

Report •

#1
August 9, 2012 at 02:05:16
"Delete Column 41 (move everything after this left)"

N2 needs to know.

Does this mean col 42 becomes 41 etc?

Post a few lines.


====================================
Life is too important to be taken seriously.

M2


Report •

#2
August 9, 2012 at 05:55:55
That is correct...

5200888888888888888808/03/2012 640440304 PPDPAYROLL 123456789012 7777777770000001

5200888888888888888808/03/2012 1640440304PPDPAYROLL 123456789012 7777777770000001

First is edited format second is unedited format


Report •

#3
August 11, 2012 at 15:19:15
your column specs did not match your sample specs, so I tried to make this easy and obvious to modify.
:begin script

@echo off>newfile & setlocal enabledelayedexpansion
set a52_1=41
set a52_2=50
set a82_1=45
set a82_2=54
for /f "tokens=*" %%a in (file) do (
set c=%%a
set test=!c:~0,2!
call :!test! 2>nul
>>newfile echo !c!
)
goto :eof

:52
:82
set x=!a%test%_1!
set y=!a%test%_2!
set /a b=x-1
set /a mid=y-x
set c=!c:~0,%b%!!c:~%x%,%mid%! !c:~%y%!
:end


Report •

Related Solutions

#4
August 12, 2012 at 06:21:34
:: ===== script starts here ===============
::
:: Jerrya.bat 2012-08-11 15:19:25.46
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in (j1) do (
set S=%%a
set F=!S:~0,2!
if "!F!" equ "52" call :sub1
>> newfile echo !S!
)
goto :eof

:sub1
set A=!S:~0,40!
set B=!S:~41!
set S=!A!!B!
set A=!S:~0,50!
set B=!S:~50!
set S=!A! !B!
goto :eof
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question