• Login
Community
  • Login

Sperate Columns From Single String

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 4 Posters 463 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.
  • J
    Jack Patil
    last edited by Jack Patil Jan 23, 2023, 8:36 AM Jan 23, 2023, 8:34 AM

    Source Data

    Cust_Id,Cust_Name,Cust_Address,Cust_Salary
    1,Name1,Address,12,Road,40,10000
    2,Name2,Address,3,20,20000
    

    Desired Output

    Cust_Id|Cust_Name|Cust_Address|Cust_Salary
    1|Name1|Address,12,Road,40|10000
    2|Name2|Address,3,20|20000
    

    I want to Separate Data Column Wise and Instead of Comma I want Pipe Delimiter, How to do that in Notepad++

    D 1 Reply Last reply Jan 23, 2023, 8:52 AM Reply Quote 1
    • D
      dinkumoil @Jack Patil
      last edited by dinkumoil Jan 23, 2023, 8:54 AM Jan 23, 2023, 8:52 AM

      @Jack-Patil

      04ddb9c7-1f54-4580-a7f6-63a373382cb9-grafik.png

      Provided that the Cust_Name column contains no (comma-separated) multi-part content:

      Find what: ^(.+?),(.+?),(.+),(.+?)$
      Replace with: $1\|$2\|$3\|$4

      J 1 Reply Last reply Jan 23, 2023, 9:40 AM Reply Quote 5
      • J
        Jack Patil @dinkumoil
        last edited by Jan 23, 2023, 9:40 AM

        @dinkumoil Thanx a Lot it’s Working Perfectly.

        1 Reply Last reply Reply Quote 2
        • A
          Alan Kilborn
          last edited by Jan 23, 2023, 12:10 PM

          @dinkumoil 's solution works great.

          Just a note to say that | is not a “special character” when used in the Replace with part of a regular expression. Thus it does not need to be “escaped” with \.

          In other words, this would have worked just as well for the Replace with:

          $1|$2|$3|$4

          D 1 Reply Last reply Jan 23, 2023, 12:53 PM Reply Quote 4
          • G
            guy038
            last edited by Jan 23, 2023, 12:18 PM

            Hello, @jack-patil, @dinkumoil, @alan-kilborn and All,

            An other solution could be :

            SEARCH ,(?=.*Address|Cust)|,(?=\d+$)

            REPLACE |

            BR

            guy038

            A 1 Reply Last reply Jan 23, 2023, 12:24 PM Reply Quote 0
            • A
              Alan Kilborn @guy038
              last edited by Alan Kilborn Jan 23, 2023, 12:45 PM Jan 23, 2023, 12:24 PM

              @guy038 said in Sperate Columns From Single String:

              ,(?=.*Address|Cust)|,(?=\d+$)

              I don’t think that will work on real data.
              I’ve got to believe that OP has used Name1, Address, etc. as mockups in the data (below the obvious “header” line at the top), to avoid publishing sensitive data?

              1 Reply Last reply Reply Quote 2
              • G
                guy038
                last edited by guy038 Jan 23, 2023, 12:47 PM Jan 23, 2023, 12:46 PM

                Hello, @jack-patil, @dinkumoil, @alan-kilborn and All,

                Yes, Alan, you’re certainly right about it ! Indeed, the strings Name1, Name2 and Address seem to be generic terms !

                Just thought of this text, in a literally way. My bad :-((

                BR

                guy038

                A 1 Reply Last reply Jan 23, 2023, 12:50 PM Reply Quote 2
                • A
                  Alan Kilborn @guy038
                  last edited by Alan Kilborn Jan 23, 2023, 12:51 PM Jan 23, 2023, 12:50 PM

                  @guy038 said in Sperate Columns From Single String:

                  Just thought of this text, in a literally way.

                  No worries!
                  Not only do we have to solve problems (if we choose to reply), we also have to “play detective” to know what a poster is and isn’t saying with their descriptions, even when they put their data in a nice code block.

                  1 Reply Last reply Reply Quote 2
                  • D
                    dinkumoil @Alan Kilborn
                    last edited by Jan 23, 2023, 12:53 PM

                    @Alan-Kilborn said in Sperate Columns From Single String:

                    | is not a “special character” when used in the Replace with part of a regular expression

                    Hmm, you are right. Don’t know how, but in some way I had in mind that it is required. Anyway, good to know that it is not.

                    A 1 Reply Last reply Jan 23, 2023, 1:08 PM Reply Quote 3
                    • A
                      Alan Kilborn @dinkumoil
                      last edited by Alan Kilborn Jan 23, 2023, 1:10 PM Jan 23, 2023, 1:08 PM

                      @dinkumoil said in Sperate Columns From Single String:

                      Hmm, you are right. Don’t know how, but in some way I had in mind that it is required. Anyway, good to know that it is not.

                      It really IS hard to keep all this regular expression syntax straight. :-(

                      I wasn’t pointing it out to pick apart your regular expression, though.

                      People learn new things from what they see here, even if it isn’t their question.
                      \| works…but if people can know they can write replacement expressions in Notepad++ involving | without a bunch of leaning toothpicks , then so much the better.

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