Community
    • Login

    Replace all entries in a row

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 255 Views 2 Watching
    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.
    • Muhammad Nihal NaseerM Offline
      Muhammad Nihal Naseer
      last edited by

      Hi everyone, I have a .txt file containing multiple rows and columns. For a particular row, I want to keep the first value unchanged and replace every other value in that row with a fixed number.

      Example:

      Original row:
      Ns 0 1 2 3 4

      Desired row:
      Ns 1 1 1 1 1

      Any suggestions would be appreciated—thanks!

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @Muhammad Nihal Naseer
        last edited by

        @Muhammad-Nihal-Naseer ,

        Unfortunately, your example data (both before and after) wasn’t good enough to clarify what you wanted.

        There are lots of regex that will do what you want on that specific piece of data. But until you define what you actually want under multiple conditions, it will be impossible to make you happy.

        For example,

        • Is Ns what causes it to be “a particular row”
        • Is it possible for there to be “a particular row” that has something other than five numbers
        • Are all your numbers single digits? Or can some of them be multiple digits (like Ns 0 11 2 33 4444)?
        • Are there any spaces before the Ns?
        • Are those spaces or tabs between columns?

        The best advice for asking for search/replace help is to give a block of data, showing both things that change, and things that should stay the same.

        For example,

        Ms 0 1 2 3 4
        Ns 0 1 2 3 4
        Ps 0 1 2 3 4
        

        would work (by my definition, based on my interpretation of your incomplete spec) with

        • FIND = ^(Ns) \d \d \d \d \d
        • REPLACE = $1 1 1 1 1 1
        • SEARCH MODE = Regular Expression

        ending up with

        Ms 0 1 2 3 4
        Ns 1 1 1 1 1
        Ps 0 1 2 3 4
        

        … but it would do nothing to the text

        Ms 0 1 2 3 4
        Ns 0 11 2 33 4444
        Ps 0 1 2 3 4
        

        Assuming the rule is “match a line starting with Ns followed by 5 integers of 1 or more digit each”, the FIND would be ^(Ns) \d+ \d+ \d+ \d+ \d+ and the REPLACE would be as I described above. That updated FIND would then turn the “do nothing” text the same way my original did.

        But it all depends on what your real data looks like.

        -—

        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 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors