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 :

"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

Reply ↓  Report •

February 25, 2018 at 12:13:22
You got an answer here ==>
since you don't provide more and clear information you can't get the best answer as you want

Reply ↓  Report •

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")
'wscript.echo p
'wscript.echo p2
wscript.echo out
'end vbscript

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

Reply ↓  Report •

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
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 '************************************************
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
exit /b

Reply ↓  Report •

Related Solutions

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")
wscript.echo out

Reply ↓  Report •

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%
::----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
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1340c/1965m BiosMod

Reply ↓  Report •

Ask Question