• Login
Community
  • Login

Need to replace a line feed character in column 86

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 4 Posters 310 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    Mark Boucher
    last edited by PeterJones Nov 15, 2023, 8:15 PM Nov 15, 2023, 7:18 PM

    Fellow Notepad++ Users,

    Could you please help me the the following search-and-replace problem I am having?

    I need to replace the line feed LF character in column 86 (after MM/YY before *01) on multiple lines, but retain the LF in other columns.

    Here is the data I currently have (“before” data):

    00001-999           UPH MEDICAL GOWN MATERIAL         B   1 YDS      1     2550  4/20
    *01                  3.90
    00002-599           29340 VENTILATED MESH WHITE       B   1 YDS      1       11  7/16
    *01       12.1       6.00
    00002-999           UPH KNIT TRIM FOR GOWNS           B   1 YDS      1           4/20
    *01
    00003-999           04043-060 FABRIC MAXIMA ESD MEDI  B   1 YDS      1     2550  4/20
    *01       34.4       3.90
    

    Here is how I would like that data to look (“after” data):

    00001-999           UPH MEDICAL GOWN MATERIAL         B   1 YDS      1     2550  4/20 *01                  3.90
    00002-599           29340 VENTILATED MESH WHITE       B   1 YDS      1       11  7/16 *01       12.1       6.00
    00002-999           UPH KNIT TRIM FOR GOWNS           B   1 YDS      1           4/20 *01
    00003-999           04043-060 FABRIC MAXIMA ESD MEDI  B   1 YDS      1     2550  4/20 *01       34.4       3.90
    

    To accomplish this, I have tried using the Begin/End Select in Column Mode

    I was able to highlight all LF characters in Notepad++ when I show all symbols but I was not able change the LF character

    Unfortunately, this did not produce the output I desired, and I’m not sure why. Could you please help me understand what went wrong and help me find the solution?

    Many thanks !!

    T C 2 Replies Last reply Nov 15, 2023, 7:46 PM Reply Quote 1
    • T
      Terry R @Mark Boucher
      last edited by Terry R Nov 15, 2023, 7:47 PM Nov 15, 2023, 7:46 PM

      @Mark-Boucher said in Need to replace a line feed character in column 86:

      Could you please help me understand what went wrong and help me find the solution?

      So it should be relatively easy since you state it’s before the *01 (in every line). I would ask though that you ONLY want a LF to be removed. If this file has come from non-windows source that would correct, however in Windows it’s very likely it’s a LF following a CR (carriage return).

      You could try the following (search mode regular expression) using the Replace function.
      Find What:\n(?=\*01)
      Replace With: empty field, nothing here

      Note the \n is a LF, but if as I say it needs that and CR removed, replace this with \R

      Terry

      1 Reply Last reply Reply Quote 4
      • M
        Mark Olson
        last edited by Nov 16, 2023, 2:24 AM

        If you want to replace REGEX (where REGEX is any regular expression) starting in the n^th column of any file, the general regex is (?-s)(?<=^.{n})REGEX.

        Note that this is potentially rather slow if n is large and REGEX has a lot of matches, because the lookbehind will check up to n characters on every match.

        So in this case, you would search (?-s)(?<=^.{86})\n, unless you’re saying that the first column of the line is column 1, in which case it’s (?-s)(?<=^.{85})\n

        1 Reply Last reply Reply Quote 2
        • C
          Coises @Mark Boucher
          last edited by Nov 16, 2023, 4:04 AM

          @Mark-Boucher said in Need to replace a line feed character in column 86:

          the line feed LF character in column 86 (after MM/YY before *01)

          If the pattern is consistent that you have one or two digits, a diagonal, two digits, a line break, and “*01” at the beginning of the next line, then just select Search | Replace… from the menu, enter:

          Find what : (?<=\d/\d\d)\R(?=\*01)
          Replace with : a single space
          Search Mode: Regular expression

          and use the Replace All button.

          If that gets other sorts of lines that you didn´t want wrapped, then it can be refined, or you can use the counting characters method @Mark-Olson explained.

          @Mark-Boucher said in Need to replace a line feed character in column 86:

          To accomplish this, I have tried using the Begin/End Select in Column Mode

          Rectangular selections won’t work for this, for a couple of reasons. For one thing, you can’t select or change line endings using rectangular selections. In addition, you’re not just selecting the long lines, you’re also selecting “virtual space” past the end of the short lines.

          1 Reply Last reply Reply Quote 1
          4 out of 4
          • First post
            4/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors