I
I
inscriptios2013-12-01 11:38:11
DOS
inscriptios, 2013-12-01 11:38:11

Double quotes in sed regular expressions in a DOS environment

Hello dear!
Started learning the Win32 port of sed for a few trivial tasks. And almost immediately I ran into a problem (which, I think, is not surprising). Reading various resources and doing all kinds of searching does not help, and there is no time for deep study of regular expressions (where there is probably an answer). Please help!
Problem
There is a file containing the following line:

if file_getprop("/system/build.prop","ro.build.display.id")!="ROM v.6.0 beta" then

It is necessary to find this line using a Windows batch file using sed and replace part 6.0 betawith the value of the variable set when starting the batch file, while the specified part can be of any length, for example, 6.0 alphaand may not contain alphabetic characters, for example, 6.0. To solve the problem in a single-line script, I wanted to use the symbol " (double quotes), however, in this case, the utility does not work correctly.
The contents of the batch file:
@echo off

set MOD=d:\ROM\KITCHEN\MOD
set UnxUtils=d:\ROM\KITCHEN\TOOLS\UnxUtils\usr\local\wbin
set TEMP=d:\ROM\KITCHEN\TEMP

set /p ROMVER=Введите версию прошивки: 

%UnxUtils%\sed.exe -e "/ROM/s/v\..*"/v.%ROMVER%"/g" %MOD%\META-INF\com\google\android\aroma-config > %TEMP%\aroma-config
move /y %TEMP%\aroma-config %MOD%\META-INF\com\google\android\aroma-config

pause

When using the above code, if the original string looks like this:
if file_getprop("/system/build.prop","ro.build.display.id")!="ROM v.6.0 beta" then

and the variable ROMVER takes the value equal to 1.0, then the output is the following:
if file_getprop("/system/build.prop","ro.build.display.id")!="ROM v.1.0

which is clearly not what is expected. As far as I understand, the UNIX implementation of sed does not have this problem, because the sed script is enclosed in single quotes and using double quotes in the body of the script does not lead to such consequences...
I would appreciate any help, thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inscriptios, 2013-12-07
@inscriptios

Answered on another resource, two things had to be done:
1. Use a newer version of the sed utility.
2. Replace the quotes in the body of the script with \x22.
The final code should look like this:

@echo off
set MOD=d:\ROM\KITCHEN\MOD
set UnxUtils=d:\ROM\KITCHEN\TOOLS\UnxUtils\usr\local\wbin
set TEMP=d:\ROM\KITCHEN\TEMP
set /p ROMVER=Введите версию прошивки: 
%UnxUtils%\sed.exe -e "/ROM/s/v\..*\x22/v.%ROMVER%\x22/g" %MOD%\META-INF\com\google\android\aroma-config > %TEMP%\aroma-config
move /y %TEMP%\aroma-config %MOD%\META-INF\com\google\android\aroma-config
pause

or even better like this:
@echo off
set MOD=d:\ROM\KITCHEN\MOD
set UnxUtils=d:\ROM\KITCHEN\TOOLS\UnxUtils\usr\local\wbin
set TEMP=d:\ROM\KITCHEN\TEMP
set /p ROMVER=Введите версию прошивки: 
%UnxUtils%\sed.exe -e "/ROM v/s/\(ROM v\.\)[^\x22]*\x22/\1%ROMVER%\x22/g" %MOD%\META-INF\com\google\android\aroma-config > %TEMP%\aroma-config
move /y %TEMP%\aroma-config %MOD%\META-INF\com\google\android\aroma-config
pause

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question