This can be done easily with any text editor supporting regular expressions by searching for
\W+(\w+)\W+(\w+)$
and using as replace string ,$1,$2
.
How can you find and replace text in a file using the Windows command-line environment? contains in one answer the link to latest version of JREPL.BAT written by by Dave Benham which makes it possible to make this modification on the file using the regular expression search and replace strings.
For usage of JREPL.BAT from within a batch file with this additional batch file in same directory as the executed batch file:
call "%~dp0jrepl.bat" "\W+(\w+)\W+(\w+)$" ",$1,$2" /F "%~1" /O -
"%~1"
references here in this generic command line the name of the file to modify.
Run jrepl.bat /?
for help on the other options used here.
Run call /?
for help on this command and explanation of %~dp0
(drive and path of current batch file ending with a backslash).
Explanation of the regular expression replace:
\W+
... find 1 or more non word character according to Unicode standard.
(\w+)
... find 1 or more word character according to Unicode standard and mark the found string for back-referencing in replace string with $1
.
\W+
... find again 1 or more non word character according to Unicode standard.
(\w+)
... find again 1 or more word character according to Unicode standard and mark the found string for back-referencing in replace string with $2
.
$
... search expression results in a positive match only if the two words could be found at end of a line whereby the newline characters are not matched.
For a line like
Check Subsystem version 3.1.8-11P
which should be modified to
Check Subsystem,version,3.1.8-11P
in the file a different regular expression search string is necessary because of .
and -
are non word characters according to Unicode standard.
The search string must be modified to: [^\w.\-]+([\w.\-]+)[^\w.\-]+([\w.\-]+)$
[
...]
is positive character class definition matching any character specified within the square brackets.
[^
...]
is a negative character class definition matching any character not specified within the square brackets.
\w
is a special character class definition for all word characters according to Unicode standard.
.
inside square brackets of a positive or negative character class definition is interpreted as literal character. The dot character would have a special meaning in regular expression search strings outside a character class definition.
-
inside square brackets of a positive or negative character class definition means all characters from character X specified left to -
to character Y specified right to -
according to code values of the characters X and Y. The hyphen is interpreted also as literal character if there is no character either left or right to -
inside the character class definition. However, it is advisable to escape -
with a backslash inside a character class definition independent on its position within the brackets when the hyphen character should be interpreted as literal character. Outside a character class definition the hyphen character has no special meaning.
So the entire command line to use for a file containing strings with dot and hyphen which should be interpreted as "words" is:
call "%~dp0jrepl.bat" "[^\w.\-]+([\w.\-]+)[^\w.\-]+([\w.\-]+)$" ",$1,$2" /F "%~1" /O -