Working on a batch script that will modify package.json file.
Basically, I need to replace the "test" portion of every json file.
This is a sample snippet:
"scripts": {
"test": "any text can go here"
},
What I want to do is replace the entire "test" line with:
"test": "jest --coverage"
I have only come up with a script that replaces a string (without spaces):
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in (temp.txt) do (
SET s=%%a
SET s=!s:test=newText!
echo !s!>>yourtempfilename.txt
)
pause
Can anyone help me modify this so that:
- it can accommodate a string with spaces
- it can replace the entire line with "test" considering "any text can go here" value is always different
Please note though that I cannot use any other programs/commands such as sed or fnr.bat or something.
cmd.execommands, usepowershell.exewith itsConvertFrom-JsonandConvertTo-Jsonfunctionality instead.jrepl "test" "replacement text" /l /b /e /f "temp.txt" /o -test, but the unknown string thereafter. (no doubt,jreplcan do that too though)