• Login
Community
  • Login

Help formatting text!? Possible in notepad++?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 3 Posters 1.2k 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.
  • B
    brandon schwartz
    last edited by Jul 24, 2019, 8:19 PM

    I have a range of data that was supposed to be formatted as Part#|All prices, however the prices got listed vertically in a list.

    The data was supposed to look like this: Part123 | 10$ 11$ 12$ 13$

    But it looks like this Part123|10$
    11$
    12$

    I quickly figured out that there didn’t seem to be a method to fix this via excel so I opened it in notepad and got.

    Part123
    10$
    11$
    12$
    13$
    Part456
    14$
    15$
    16$

    What I need is the average of all prices and the lowest price from every set. I have about 3,000 part numbers. Is there any way to automatically format this?

    A 1 Reply Last reply Jul 24, 2019, 8:40 PM Reply Quote 0
    • A
      Alan Kilborn @brandon schwartz
      last edited by Jul 24, 2019, 8:40 PM

      @brandon-schwartz said:

      The data was supposed to look like this: Part123 | 10$ 11$ 12$ 13$

      You could likely recover the above formatting, but Notepad++ can’t help you with:

      the average of all prices and the lowest price from every set

      1 Reply Last reply Reply Quote 1
      • T
        Terry R
        last edited by Terry R Jul 24, 2019, 9:31 PM Jul 24, 2019, 9:31 PM

        @brandon-schwartz said:

        The data was supposed to look like this: Part123 | 10$ 11$ 12$ 13$

        As @Alan-Kilborn said Notepad++ can help with fixing the formatting (see my regex below), but cannot help with calculations as Notepad++ itself does NOT have a mathematical ability.

        So to get the formatting back to how you’d like it my regex is:
        Find What:(?-s)(part\d+$)|(\R(\d+\$))
        Replace With:(?1\1 \|)(?3 \3)

        As this is a regex you need the search mode in “regular expression”. Once the 2 fields are entered (can copy the red text and paste) just pres the “Replace All” button once, the whole file should be reformatted. Suggest have the cursor in the very first position of the first line, otherwise the “wrap around” would need to be enabled (most have that enabled already anyways).

        As a bit of background, the regex uses alternation. Thus it can search for different types of text and the replace field can interpret which option was selected and based on that respond with a different set of replacements. You will note that some of the characters have a \ in front, and sometimes not. That’s because I cam using the characters in 2 different modes. For example the $ by itself means a zero length position at the end of a line, as \$ it means literally a dollar sign.

        Good luck

        Terry

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