VBS theoretical line length is 2,000,000,000 bytes (or 1 x 2^30 characters). You'll never get anywhere near that (the actual is largest block of free contigious memory - it will be millions of characters).
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
'Remove ^ from quoting command line. Quote, ampersand and brackets
Pttn = Replace(Arg(2), "^(", "(")
Pttn = Replace(Pttn, "^)", ")")
Pttn = Replace(Pttn, "^&", "&")
Pttn = Replace(Pttn, "^""", """")
Set regEx1 = New RegExp
If Instr(LCase(Arg(1)), "i") > 0 then
regEx1.IgnoreCase = True
Else
regEx1.IgnoreCase = False
End If
regEx1.Global = False
regEx1.Pattern = Pttn
Do Until Inp.AtEndOfStream
Line=Inp.readline
Line = RegEx1.Replace(Line, Arg(3))
outp.writeline Line
Loop
How to use.
Replace
filter replace {i|n} expression replace
filter repl {i|n} expression replace
Finds and replaces text using regular expressions.
Also used to extract substrings from a file.
Ampersands and brackets in expression must be escaped with the caret. Do not escape carets. Use hexidecimal code \x22 for quotes.
SearchOptions
i - ignore case
n - none
Expression
https://msdn.microsoft.com/en-us/library/ae5bf541(v%3Dvs.90).aspx
Replace
The text to replace. Use $1, $2, $..., $n to specify sub matches in the replace string
Example
filter replace i "=" "No equal sign" < "%systemroot%\win.ini"
This searches for text within square brackets and replaces the line with cat followed by the text within brackets
Filter replace i "^\[^(.*^)\]" "cat$1" < %windir%\win.ini
This searches for any text and prints from the 11th character to the end of the line.
Filter replace i "^.{10}^(.*^)$" "$1" < %windir%\win.ini
This searches a CSV file and prints the second and fourth field
Filter replace i "^.+,^(.+^),.+,^(.+^)$" "$1,$2" < csv.txt
Filter reads and writes standard in and standard out only. These are only available in a command prompt.
filter <inputfile >outputfile
filter <inputfile | other_command
other_command | filter >outputfile
other_command | filter | other_command
Download full source here https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121