Solved Batch to delete 190 first characters in a text file

July 11, 2012 at 10:48:07
Specs: Windows XP
Dear all,
I'm Alex from Indonesia.
I need help to create a batch file to delete 190 first characters in a text file.
the 190 chars contain numberic, space, chars. the file contains more than 1000 chars.
Hope the batch is working for Windows 2003 and 2008 server.
Thanks in advance.

See More: Batch to delete 190 first characters in a text file

Report •


#1
July 11, 2012 at 11:19:32
Is the column width of the file 190 characters or is 190 spread across multiple lines?

Tony


Report •

#2
July 11, 2012 at 19:02:34
the file has 4-5 lines... I need to remove the first 190 chars.
the 190 chars are in line 1 and 2.
many thanks

Report •

#3
July 12, 2012 at 06:53:00
✔ Best Answer
:: ===== script starts here ===============
::
:: drop190.bat 2012-07-12 20:37:49.25
@echo off & setLocal enableDELAYedeXpansioN

set N=
for /f "tokens=* delims= " %%a in (some.txt) do (
set /a N+=1
if !N! lss 3 set S=!S!%%a
)
> outfile echo.!S:~190!

for /f "tokens=* skip=2 delims= " %%a in (some.txt) do (
echo.%%a
) >> outfile

goto :eof

::====== script ends here =================


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

M2


Report •

Related Solutions

#4
July 20, 2012 at 05:26:29
Hi M2,
I put your script in Windows Scheduler but problem came.
if the script didnt find any file to be cut, it will create a new file.
could you please help to modify the script to be able to check if the file is available or not.
many thanks for your help.
Alex

Report •

#5
July 25, 2012 at 02:54:08
if not exist some.txt echo no file && goto :eof


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

M2


Report •

#6
July 25, 2012 at 08:07:34
:: ===== script starts here ===============
::
:: drop190.bat 2012-07-12 20:37:49.25
@echo off & setLocal enableDELAYedeXpansioN
set N=
for /f "tokens=* delims= " %%a in (some.txt) do (
set /a N+=1
if !N! lss 3 set S=!S!%%a
)
> outfile echo.!S:~190!

for /f "tokens=* skip=2 delims= " %%a in (some.txt) do (
echo.%%a
) >> outfile
if not exist some.txt echo no file && goto :eof

has tested but the result : outfile created


Report •

#7
July 25, 2012 at 20:58:59
move the last line ("if not exist...") to be the second line of script, just under "@echo off..." line. Should fix.

Report •


Ask Question