0

Im trying to use REPL.BAT to delete the linefeed found in the file.

Now I have this code

Type "C:\user\AllFiles\%%a.in.tmp"  | C:\user\bat\repl.bat "%%s" "%%t" X > "C:\user\AllFiles\%%a.out.tmp"




%%s - Can be found in the first column of replace.txt
%%t - Can be found in the second column of replace.txt

Note that that below example matches pattern starts with AAA+any 3 chars and replaced with XXXYYY

AAA\d{3}     XXXYYY

Now how will I implement replacing the \R with NULL?

Community
  • 1
  • 1
PeterS
  • 724
  • 2
  • 15
  • 31

2 Answers2

1

LineBreaks

filter fix {lf|cr}

Fixes problems with line endings.

Lines are broken at the line feed character. If preceded by a carriage return both are removed. However a single carriage return without a line feed does not break the line.

cr - removes all stray CR and LF left on each line.

lf - add a LF to any CR embeded in the middle of the line.

It then writes the line with a CRLF at the end (the writeline method adds it).

Example Fixes win.ini, not that it needs fixing, and sends it to the screen

filter fix cr <"%systemroot%\win.ini"

You'll have to modify script as it expects command line arguments.

Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout

    If Arg(1) = "cr" then 
        Do Until Inp.AtEndOfStream
            Line=Inp.readline
            Line=Replace(Line, vbcr, "")
            Line=Replace(Line, vblf, "")
            outp.writeline Line
        Loop
    End If
    If Arg(1) = "lf" then 
        Do Until Inp.AtEndOfStream
            Line=Inp.readline
            Line=Replace(Line, vbcr, vbcrlf)
            outp.writeline Line
        Loop
    End If

To use you need to run with cscript.

cscript //nologo c:\scriptname.vbs fix cr <inputfile.txt >outputfile.txt

I'm sure you can modify it. Regular Expressions are overkill for this.

0

You have not provided enough information for anyone to provide the full answer.

In general, you must use the M (multi-line) option if you want to manipulate \n (linefeed).

The following will remove all \r\n and/or \n from a file. Adapt as needed.

type file.txt|repl "\r?\n" "" m >out.txt
dbenham
  • 127,446
  • 28
  • 251
  • 390