3

I have a pipe delimited file with 35 pipes per line.There is an expected line feed after the 35th field. For example:

FirstField|ME|HERE|PHONE|Description|.....|LastField
FirstField|YOu|THERE|PHONE|Description|.....|LastField

However, some of the data between pipes (for example in a description field) contains line feeds. Eg:

FirstField|Them|Where|PHONE|This contains a
LineFeed
Or two
or more|.....|LastField

Question is, how to remove the Line Feeds in any of the 35 fields, but not at the end of the line?

(Off note: I'm working in Notepad++ for testing)

Dylan Wheeler
  • 6,928
  • 14
  • 56
  • 80
ACesario
  • 89
  • 9

1 Answers1

5

You may leverage the Notepad++ PythonScript plug-in.

See instructions on how to install a working version here and create the following script file:

def repl(match):
    return match.group(0).replace("\r\n", "").replace("\n", "").replace("\r", "")

editor.rereplace(r'^[^|]*(?:\|[^|]*){36}$', repl)

If you name the script file as replace_lbr_inblock.py, you will be able to call it by selecting Plugins -> Python Script -> Scripts -> replace_lbr_inblock.

The regex ^[^|]*(?:\|[^|]*){36}$ matches

  • ^ - start of the line
  • [^|]* - zero or more chars other than |
  • (?:\|[^|]*){36} - 36 sequences of a | followed with zero or more pipes
  • $ - end of line.

Before:

enter image description here

After:

enter image description here

Community
  • 1
  • 1
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • This can only break if there is a `|` inside your data, or the number of columns is not fixed (although it is mentioned the number of columns is fixed). Please let know if it is possible that `|` inside the data is possible (in an escaped form?). – Wiktor Stribiżew Jul 19 '16 at 21:39