Community
    • Login

    Format name and password from vertical to horizontal

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 252 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.
    • G
      gomasafrat
      last edited by PeterJones

      I have a text file that contains lines containing usernames and passwords as follows

      USERNAME= 4195236386
      
      PASSWORD= 378321883
      
      USERNAME= 412247706
      
      PASSWORD=8753804400
      
      USERNAME= Aymanmoo0103
      
      PASSWORD= Aymoo121212
      
      USERNAME= OmarZanaty
      
      PASSWORD= Z1z2z3z4
      

      The file is large and I want to format it to be like
      this

      USERNAME= 4195236386PASSWORD= 378321883
      
      USERNAME= 412247706PASSWORD=8753804400
      
      USERNAME= Aymanmoo0103PASSWORD= Aymoo121212
      
      USERNAME= OmarZanatyPASSWORD= Z1z2z3z4
      

      Or this format

      USERNAME= 4195236386 PASSWORD= 378321883
      
      USERNAME= 412247706 PASSWORD=8753804400
      
      USERNAME= Aymanmoo0103 PASSWORD= Aymoo121212
      
      USERNAME= OmarZanaty PASSWORD= Z1z2z3z4
      

      —

      moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @gomasafrat
        last edited by PeterJones

        @gomasafrat ,

        1. The forum has a post-queue to prevent spammers: the post-editor told you this as you were creating your post. You don’t have to post it twice just because you didn’t see it show up visibly. I used moderator power to only approve the first version you posted, not the second version,

        2. Please use the </> on the post toolbar for marking your example text as “code”, which makes sure that the forum puts it in the box and doesn’t interpret text as formatting codes. I used moderator power to add in the markdown for you, so that people could read your text to help you, but in the future, you need to be the one to make your post readable.

        3. I cannot tell whether you really meant for there to be blank lines between each line of text, or if that was some artifact of the way you entered the text. You need to clarify this, otherwise the answers we give might not work for your actual data.

        4. I cannot tell whether you really intended for the word PASSWORD to be squished together with the username’s value in the first possible output format; if that’s what you want, it seems like a horrible idea to me, so I will assume you don’t actually want it that way.

        5. From a data security standpoint, you should never store passwords in plain text. If you are, you are either asking hackers to steal your list of passwords, or you are a hacker who has already hacked some site. The first is highly insecure, the second is immoral and likely illegal. I will assume this is just an example set of data, where you are trying to learn how to do that, and that you are neither practicing insecure behavior nor criminal behavior.

        Possible solution:
        FIND = (?-s)^(USERNAME=.*)\R+(PASSWORD=.*)$
        REPLACE = $1 $2
        SEARCH MODE = Regular Expression
        REPLACE ALL

        This should work whether or not you have the extra blank lines between each line.

        quick explanation:
        FIND:

        • (?-s) = makes sure you are not in . matches newline mode, no matter what the setting is in your REPLACE dialog
        • ^ = matches beginning of the line (so USERNAME= must be at the start of the line, no blank space or other characters before it
        • (...) = store whatever is matched inside in a group for the replacement. There are two of these, so you have group1 and group2
        • .* = match 0 or more of any type of characters
        • \R+ = match 1 or more newline sequences
        • $ = match the end of the line, so group2 will go all the way to the end of its line

        REPLACE:

        • $1 = use the contents of group1
        • $2 = use the contents of group2
        • since the newline sequences between the groups weren’t in any group, they won’t end up in your replacement

        The references below – especially the User Manual’s regex docs – will help you learn more about regular-expression searching.

        ----

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 2
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors