add/delete text in txt files with batch

May 17, 2010 at 13:44:56
Specs: Windows 7
hello, i have a lot of txt files with this layout:

number number
number number

whith a lot of number lines and a bad formatting.
I need a batch program that:
-deletes the line with text (the firs row)
-deletes the 5 spaces before the first number
of each line and replaces the 4 spaces
between the 2 numbers of each line with a
single space character
- add a 0 at the end of each line of numbers, obviously with a space before.
the output (overwrited to the original file)
should be like this:
number number 0
number number 0
How can i do that? can anyone help me?

See More: add/delete text in txt files with batch

Report •

May 17, 2010 at 14:16:48
If you store the following batch as e.g. myedt.bat, at prompt type

myedt "PathName/FileName"

Don't miss the double quotes.

@echo off > ""
for /F "skip=1 tokens=1,2" %%a in ('type "%~f1"') do (
  echo.%%a %%b 0>> ""
del "%~f1"
ren "" "%~nx1"

Report •

May 17, 2010 at 14:22:58
@echo off>new & setlocal
for %%a in (*.txt) do (
for /f "skip=1 tokens=1-2" %%b in (%%a) do >> new echo %%b %%c 0
more new
@:: move /y new %%a
::----- note that file replacement is disabled pending testing!

ps: oops! crossed in the mail.

Report •

May 17, 2010 at 15:44:23
thanks nbrane. on cmd your code does exactly what i want. how
to overwrite the original txt file with the new one, and this for
each txt file? sorry but i don't know anything about batch

Report •

Related Solutions

May 17, 2010 at 15:58:10
@:: move /y new %%a
the above line, make it like this:
move /y new %%a

strongly suggest backing up the files to a temp directory
first, in case of problems.
easy enough, from the directory where the files are:
md .\temp
copy *.* temp

Report •

May 17, 2010 at 16:23:02
ok now it's perfect! thank you:)

Report •

Ask Question