A Batch-JScript hybrid script solution!
EDIT: Small bug fixed (didn't separate lines!)
Code: Select all
@set @Batch=1 /*
@echo off
setlocal EnableDelayedExpansion
set "regExp="
set "retVal="
set /A i=1, maxSpaces=0
for %%a in (2,15,19,4,38,35,13,15,2,10) do (
set "regExp=!regExp!\t(.*)"
set "retVal=!retVal!+($!i!+spaces).substr(0,%%a)"
if %%a gtr !maxSpaces! set "maxSpaces=%%a"
set /A i+=1
)
set "regExp=/^%regExp:~2%$/gm"
set "retVal=%retVal%+'\r\n'"
CScript //nologo //E:JScript "%~F0" "%regExp%" "%retVal:~1%" %maxSpaces% < test.txt
goto :EOF */
// JScript section
var arg = WScript.Arguments, regExp = arg(0), retVal = arg(1), maxSpaces = parseInt(arg(2)), spaces = "";
for ( var i = 1 ; i <= maxSpaces ; i++ ) spaces += " ";
WScript.Stdout.WriteLine(
WScript.Stdin.Readall().replace(
eval(regExp),
function ($0,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10) {return (eval(retVal));}
)
);
This solution correctly manage the case when there is "no data", that is, when there are two TAB's together.
PS - I tried to create the function parameters in a variable and then define the function this way:
Code: Select all
function ( eval(funcParams) ) { return ...
but it marked an error. It seems that eval can not be used always; perhaps there are specific cases when certain declarations can not be performed inside an eval...
Antonio