1

In FART.exe find/replace tool, i’m having some trouble with newline char:

> set lf=^& echo.
> fart myfile.csv lf "],["
Replaced 0 occurence(s) in 0 file(s).

Nothing gets replaced. What's the correct (and simplest) way to do this? The line-terminators in the file might be CarriageReturn + LineFeed, not sure. How to check for both?

(PS, fart is the fastest replace tool i've tested on Windows. Tested much faster than repl.bat, jrepl.bat, findrepl.bat, sfk.ext, and powershell.)

Community
  • 1
  • 1
johny why
  • 2,047
  • 7
  • 27
  • 52

1 Answers1

2

edited to adapt to comments

fart includes a switch (-C or --c-style) to indicate that input/output strings contain C-style extended characters. In this case quotes are not needed around the search or replacement strings as there are no special characters in the command line:

fart -C myfile.csv \r\n ],[
MC ND
  • 69,615
  • 8
  • 84
  • 126
  • this might be the answer! I'm getting proper `"Replaced x occurrences in file"` But, on opening the file in text editor, i'm getting `"Lines ending in solitary carriage returns detected. Possibly a Macintosh text file (it's not). Converting to UNIX format."` How to fix? I suspect the line-terminators are CarriageReturn + LineFeed, and my fart command is only replacing the LF's. – johny why Sep 20 '16 at 18:00
  • @johnywhy, then you don't want to replace new line characters (`\n`), but carriage return characters (`\r`) – MC ND Sep 20 '16 at 18:02
  • it needs both \n\r – johny why Sep 20 '16 at 18:12
  • @johnywhy, sorry, I didn't see the changes in the question. – MC ND Sep 20 '16 at 18:20
  • just curious, is CR+LF as line-terminator a Windows thing? – johny why Sep 20 '16 at 18:22
  • @johnywhy, anyway, maybe they are just needed to make data coherent, but the quotes are not needed by `fart` around the square brackets. – MC ND Sep 20 '16 at 18:23
  • @johnywhy, *`Windows thing`*? [not exactly](https://en.wikipedia.org/wiki/Newline) – MC ND Sep 20 '16 at 18:25
  • you're correct, double-quotes are not needed. Thx for the link, very useful! It says LF-only is standard line-terminator on Linux, and CR-only on Mac (up to v9). Those are the platforms of interest to me. thx! – johny why Sep 20 '16 at 18:30
  • Yes, "\r\n" is the standard line ending for DOS/Windows plain text files. – lit Sep 20 '16 at 22:56