Solved Remove 30 first char of text file

September 24, 2012 at 14:41:27
Specs: Windows XP
Hi,
I have text file and need a script to remove 30 first chars of text file.
for instance :
first line :
INFO_HADIR_SEBAGAIDARIKEJAYAAN##                              ##2043433481635##00001114##00001000,2112/09/14,10:04:28

second line :
BATHADIR,FTR,1,,,,,,,@1ST@,29120924,001395185117,0,Gerhanastama,,,,,,1100001111

third line :
SECPTY,12334567899,HANKY INTERJECTION

to be :
first line :

##                              ##2043433481635##00001114##00001000,2112/09/14,10:04:28

second line :
BATHADIR,FTR,1,,,,,,,@1ST@,29120924,001395185117,0,Gerhanastama,,,,,,1100001111

third line :
SECPTY,12334567899,HANKY INTERJECTION

I run this script :
@echo off & setLocal enableDELAYedeXpansioN
if not exist source.txt echo no file && goto :eof
set N=
for /f "tokens=* delims= " %%a in (source.txt) do (
set /a N+=1
if !N! lss 3 set S=!S!%%a
)
> 1.txt echo.!S:~30!

for /f "tokens=* skip=2 delims= " %%a in (source.txt) do (
echo.%%a
) >> 1.txt
but the second line always move to first line.
Please help
thanks

edited by moderator: Added pre tags -Razor2.3


See More: Remove 30 first char of text file

Report •

#1
September 24, 2012 at 19:20:40
✔ Best Answer
@echo off & setlocal
set file=source.txt
(echo a90
echo sub cx,1e
echo int 3
echo.
echo g=90
echo w11e
echo q ) | debug %file% > nul
::===== end

Not sure of the filesize capacity. Here's a "new and improved" alternative vbscript solution (now tested and functional!):

'''==== begin vbscript
if wscript.arguments.count <2 then
wscript.echo "usage: CSCRIPT CLIPFILE.VBS filename no_of_bytes"
wscript.echo "output goes to file 'source.out'"
wscript.quit
end if
fname=wscript.arguments(0)
noobytes=wscript.arguments(1)
set fso=createobject("scripting.filesystemobject")
set intext=fso.opentextfile(fname,1)
set otext=fso.createtextfile("source.out")
j=intext.read(noobytes)
j=intext.readall
'''this foll. line will try to prevent the CR/LF split
if left(j,1)=chr(10) then
j=mid(j,2)
end if
otext.write j
wscript.quit
'''''==== end vbscript


Report •

#2
September 25, 2012 at 00:38:22
hi NBrane,
Many thanks,
question : if i want to remove 190 chars, what script need to change?
Thanks

Report •

#3
September 25, 2012 at 01:35:46
:: ===== script starts here ===============
::
:: alex.bat 2012-09-25 15:29:18.08
@echo off > newfile & setLocal enableDELAYedeXpansioN

set/p N=how many?

for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:~%N%!
echo.!S!
) >> newfile
goto :eof
::====== script ends here =================


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

M2


Report •

Related Solutions

#4
September 25, 2012 at 02:56:07
Hi M2,
I run the script :
@echo off > newfile.txt & setLocal enableDELAYedeXpansioN
set/p N=190

for /f "tokens=* delims= " %%a in (source.txt) do (
set S=%%a
set S=!S:~%N%!
echo.!S!
) >> newfile.txt
goto :eof
but it cut nothing. Please advice.
Thanks


Report •

#5
September 25, 2012 at 03:27:50
When you did this:

set/p N=190
what did you respond with?


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

M2


Report •

#6
September 25, 2012 at 03:36:01
Hi M2,
It will create a new text file but the file as same contain as source.txt
Please advice.
thanks

Report •

#7
September 25, 2012 at 20:52:58
for the debug version:

:: change following:
echo sub cx,be
::next 3 lines are same as original, listng for context only
echo int 3
echo.
echo g=90
::then change this line
echo w1be

for vbscript version, change only this line:
j=intext.read(30)
to this:
j=intext.read(90)


or, for adaptability (cscript x.vbs source.txt 90):

file=wscript.arguments(0)
bytes=wscript.arguments(1)
set intext=fso.opentextfile(file,1)
...
j=intext.read(bytes)
'end======

refer to modified response #`1 for a better listing with improved handling. NOTE: crlf pairs could become split if the byte-count lands between the CR and the LF!


Report •

#8
October 8, 2012 at 06:38:08
Hi NBrane,
I have ran the script ::: change following:
echo sub cx,be
::next 3 lines are same as original, listng for context only
echo int 3
echo.
echo g=90
::then change this line
echo w1be

it works on Windows XP Profesional SP 3
but...
when I run on our Windows 2008 R2 64 bit, I got this error :
'debug' is not recognized as an internal or external command, operable program or batch file.
Please help.
Thanks
Alex


Report •

#9
October 8, 2012 at 07:31:58
Obviously debug isn't recognized as a proper command since it isn't supported, similar to the choice command with win xp(where the solution would be to copy choice.exe).

Report •

#10
October 9, 2012 at 03:01:22
If you'd answered my question in #5 you might not be in this mess.


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

M2


Report •

#11
October 9, 2012 at 04:37:08
Hi M2,
I have answered but maybe my english is not good.
I supposed to replied you :
I have put N=190, then run the script. it will create a new file call newfile.txt. but the newfile.txt is as same contain as source.txt.
(means : the script create new file but not succeed to cut 190char).
Please advice.
thanks
Alex

Report •

#12
October 10, 2012 at 03:20:47
Hi Alex,

You tinkered with the set/p and got it wrong. This one is hard wired for 190.

:: ===== script starts here ===============
::
:: alex.bat 2012-09-25 15:29:18.08
@echo off > newfile & setLocal enableDELAYedeXpansioN

set N=190

for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:~%N%!
echo.!S!
) >> newfile
goto :eof
::====== script ends here =================


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

M2


Report •

#13
October 10, 2012 at 06:36:07
Hi M2,
I have modified the script with your last script.
Result : it will delete 190 first chars, left 84 chars, then delete the rest text on the file.
my original file zise has 112 KB become 3KB.
Please advice.
thanks

Report •

Ask Question