Use sed on Windows to add new XML tags

To add versions tags in vcxproj and csproj files in a project you can use three batch scripts.

1) change_csproj.bat


:: Script to add new TSM version tags into csproj files
:: Get ONLY the files that contains TSMVERSION tag, and ONLY those that are in
:: tdp\agents subdir because there are also symlinks to cli subdirs.
:: Call call_sed_helper batch script to add new version tags.
:: Uses sed for Windows.
:: Link: http://gnuwin32.sourceforge.net/packages/sed.htm

@setlocal

set SANDBOX=D:\code\tsm\tdp

for /R %SANDBOX% %%f in (*.csproj) do @find "TSMVERSION" "%%f" > null && call call_sed_helper.bat %%f

@endlocal

2) change_vcxproj.bat


:: Script to add new TSM version tags into vcxproj files.
:: Get ONLY the files that contains TSMVERSION tag, and ONLY those that are in
:: tdp\agents subdir because there are also symlinks to cli subdirs.
:: Call call_sed_helper batch script to add new version tags.
:: Uses sed for Windows.
:: Link: http://gnuwin32.sourceforge.net/packages/sed.htm

@setlocal

set SANDBOX=D:\code\tsm\tdp

for /R %SANDBOX% %%f in (*.vcxproj) do @find "TSMVERSION" "%%f" > null && call call_sed_helper.bat %%f

@endlocal

3) call_sed_helper.bat


::Script to add a line after matching a pattern.
:: Download sed for Windows, unzip it to D:\Tools\sed-4.2.1-bin
:: Put that dir on the path env var.
:: Link: http://gnuwin32.sourceforge.net/packages/sed.htm
:: You can either use either
:: - replace via sed replace command (sed s), or
:: - append via sed append command (sed a).
:: sed command to append after is a\
:: sed command to append before is i\
:: Slash char needs to be escaped with backslash if pattern delimiters are //.
:: Double-quotes needs to be escaped using backslash inside the double-quotes
:: for DOS parsing. That is, the first and last double-quotes are not escaped.
:: As alternative you can use Perl command:
:: perl -MCwd -i -pe 'BEGIN {$VAR = value} s[pattern][replace-with]' file
:: Example
:: perl -MCwd -i -pe 'BEGIN {$PWD = cwd} s[^log.*][log $PWD/redis/redis.log]' conf/redis.conf

@setlocal

set path=D:\Tools\sed-4.2.1-bin\bin;%path%

::sed -i -e "s|<TSMVERSION Condition=\"'$(VERSION_BASED_OUTPUT)'=='1' And '$(BUILD_TSM_VERSION)'=='713'\">_713</TSMVERSION>|<TSMVERSION Condition=\"'$(VERSION_BASED_OUTPUT)'=='1' And '$(BUILD_TSM_VERSION)'=='713'\">_713</TSMVERSION>\n <TSMVERSION Condition=\"'$(VERSION_BASED_OUTPUT)'=='1' And '$(BUILD_TSM_VERSION)'=='714'\">_714</TSMVERSION>|g" %1

::sed -i -e "s|<BUILDFLAGVER Condition=\"'$(BUILD_TSM_VERSION)'=='713'\">BUILD_TSM_V713</BUILDFLAGVER>|<BUILDFLAGVER Condition=\"'$(BUILD_TSM_VERSION)'=='713'\">BUILD_TSM_V713</BUILDFLAGVER>\n <BUILDFLAGVER Condition=\"'$(BUILD_TSM_VERSION)'=='714'\">BUILD_TSM_V714</BUILDFLAGVER>|g" %1

sed -i -e "/<TSMVERSION Condition=\"'$(VERSION_BASED_OUTPUT)'=='1' And '$(BUILD_TSM_VERSION)'=='713'\">_713<\/TSMVERSION>/ a\ <TSMVERSION Condition=\"'$(VERSION_BASED_OUTPUT)'=='1' And '$(BUILD_TSM_VERSION)'=='714'\">_714</TSMVERSION>" %1

sed -i -e "/<BUILDFLAGVER Condition=\"'$(BUILD_TSM_VERSION)'=='713'\">BUILD_TSM_V713<\/BUILDFLAGVER>/ a\ <BUILDFLAGVER Condition=\"'$(BUILD_TSM_VERSION)'=='714'\">BUILD_TSM_V714</BUILDFLAGVER>" %1

@endlocal

Advertisements
This entry was posted in develop and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s