Sed equivalent in a .bat file

12,765

Windows batch scripting does not have any native tools that can conveniently do anything similar to sed.

You could probably use PowerShell with a simple script, or CSCRIPT with a small custom VBS or JScript script.

I would use JREPL.BAT - a regular expression text processing utility. It is pure script (hybrid batch/JScript) that runs natively on any Windows machine from XP onward. It does not require any non-native exe or com files.

Full documentation is available from the command line using jrepl /?, or jrepl /?? for paged help.

Your simple task could be performed by JREPL using:

call jrepl "," ";" /inc -1 /f abc.java /o -
Share:
12,765
Prakadeessh Arunachalam
Author by

Prakadeessh Arunachalam

Updated on June 04, 2022

Comments

  • Prakadeessh Arunachalam
    Prakadeessh Arunachalam almost 2 years

    I have a shell script (.sh) where I use the sed command to replace the last matching character in a file(I have placed the command below).

    How should I replace the command to get the same functionality in a batch file (.bat) without adding any packages/plugins (To be compatible in windows 7 and later)?

    sed -i '$ s/,/;/g' abc.java