deleting before and after character batch file

February 17, 2018 at 19:49:48
Specs: Windows 10
I was working on a batch file to extract certain characters from a file.txt and save as file2.txt :

variant":{"key":"standard","name":"Standard","short":"Std"},"
"initial "Fen":"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"fen":"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0"}]}
{"flipBoard":"Flip board","aiNameLevelAiLevel":"%1$s level %2$s","yourTurn":"Your turn","abortGame":"Abort


I want to extract the bolded characters and save it to file2.txt. deleting before and after character

what would the completed batch file looks like.

I will donate $20 bucks via paypal for the first person to correctly writes me the batch file. make sure to include paypal email. thanks

message edited by ironsurface17


See More: deleting before and after character batch file

Report •

#1
February 25, 2018 at 12:13:22
You got an answer here ==> https://www.computerhope.com/forum/...
since you don't provide more and clear information you can't get the best answer as you want

Report •

#2
February 27, 2018 at 00:41:12
If this file has no line-breaks, or random ones, then batch will be futile. Here is a vbscript to try to do what you want:

'begin vbscript "chess.vbs":

set fso=createobject("scripting.filesystemobject")
a=fso.opentextfile(wscript.arguments(0),1).readall
p=instrrev(a,"fen")+6
'wscript.echo p
p2=instr(p,a,"}]}")-2
'wscript.echo p2
out=mid(a,p,p2-p+1)
wscript.echo out
'end vbscript

then, to execute:
cscript chess.vbs file1.txt>file2.txt
and file1.txt could be any filename...


Report •

#3
February 27, 2018 at 06:53:58
@echo off
Set "Tmpvbs=%temp%\Tmpvbs.vbs"
Set "InputFile=file.txt"
Set "TmpFile=TmpFile.tmp"
Set "OutPutFile=file2.txt"
Call :Extract "%InputFile%" "%TmpFile%"
for /F "delims=" %%a in ('Type "%TmpFile%"') do (
   echo %%a
)>"%OutPutFile%"
Del "%TmpFile%"
Start "" "%OutPutFile%" & exit
::****************************************************
:Extract <InputData> <OutPutData>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"\b[^""fen:](\w*)\/(\w*).*\b"^)
echo WScript.StdOut.WriteLine Data
echo '************************************************
echo Function Extract(Data,Pattern^)
echo    Dim oRE,oMatches,Match,Line
echo    set oRE = New RegExp
echo    oRE.IgnoreCase = True
echo    oRE.Global = True
echo    oRE.Pattern = Pattern
echo    set oMatches = oRE.Execute(Data^)
echo    If not isEmpty(oMatches^) then
echo        For Each Match in oMatches  
echo            Line = Line ^& Match.Value ^& vbcrlf
echo        Next
echo        Extract = Line
echo    End if
echo End Function
echo '************************************************
)>"%Tmpvbs%"
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
exit /b
::****************************************************


Report •

Related Solutions

#4
February 27, 2018 at 18:28:58
Yes, that's a good method for making a batch do the job, although vbscript is still doing the "heavy lifting". I've used that technique for generating short helper-scripts, but ran it this way:

for /f "tokens=1 delims=[]" %%a in ('find /n "::====="^<%~n0.bat') do (
more +%%a %~n0.bat>temp.vbs
)
cscript /nologo temp.vbs file1.txt> file2.txt
goto :eof

::=====================
set fso=createobject("scripting.filesystemobject")
a=fso.opentextfile(wscript.arguments(0),1).readall
p=instrrev(a,"fen")+6
p2=instr(p,a,"}]}")-2
out=mid(a,p,p2-p+1)
wscript.echo out


Report •

#5
February 28, 2018 at 06:25:03
::----start of test.bat----
@echo off&for /f "tokens=1,* delims=:}" %%a in ('type file.txt ^| find "fen"') do set "string=%%b"
(
echo %string:~1,-4%
)>file2.txt
exit/b
::----end of test.bat----

result, file2.txt contains:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0

i5-6600K[delid]@4.814GHz/4.613GHz cache@1.385v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2808MHz@1.37v
ASUS Z170K
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1340c/1965m BiosMod
VS450


Report •

Ask Question