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 INTERJECTIONto 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 INTERJECTIONI 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
thanksedited by moderator: Added pre tags -Razor2.3
@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
::===== endNot 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
hi NBrane,
Many thanks,
question : if i want to remove 190 chars, what script need to change?
Thanks
:: ===== script starts here ===============
::
:: alex.bat 2012-09-25 15:29:18.08
@echo off > newfile & setLocal enableDELAYedeXpansioNset/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
Hi M2,
I run the script :
@echo off > newfile.txt & setLocal enableDELAYedeXpansioN
set/p N=190for /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
When you did this: set/p N=190
what did you respond with?
====================================
Life is too important to be taken seriously.M2
Hi M2,
It will create a new text file but the file as same contain as source.txt
Please advice.
thanks
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 w1befor 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!
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 w1beit 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
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).
If you'd answered my question in #5 you might not be in this mess.
====================================
Life is too important to be taken seriously.M2
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
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 enableDELAYedeXpansioNset 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
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
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |