Community
    • Login

    Setting a Column to a fixed value in a text file

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 4 Posters 3.3k 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.
    • Chuck BallingerC
      Chuck Ballinger
      last edited by

      Next to set specific column within a large text file to a specific value, say Column 10 = “X”, column 32 = “Z” etc.
      Can I do this with a macro or ??

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • cipher-1024C
        cipher-1024
        last edited by

        Yes, you probably can.

        You’re going to have to give more details about the text you’re trying to format to get a better answer than that though. What defines a ‘column’ (tabs, commas, special characters)? Are the columns encapsulated in quotes? If you can give some specifics and maybe several example lines from the text file, I’m sure you’ll get an answer that helps.

        1 Reply Last reply Reply Quote 0
        • Scott SumnerS
          Scott Sumner @Chuck Ballinger
          last edited by

          @Chuck-Ballinger

          • Put your caret in the desired column (e.g. 10) on line #1.
          • Press Shift+Alt+DownArrow until you get to the last line of your file (stay in same column).
          • You should now have what appears to be a really tall and skinny caret (assuming your are in INS mode; check status bar for INS vs OVR).
          • Type the “fixed value” character that you want to have in your desired column.
          • If you wanted to replace the original column content with your fixed-value character (rather than insert it), press the Delete key once.

          If your file has a large number of lines, there are alternative steps to the 2nd step…to make it less onerous…

          1 Reply Last reply Reply Quote 0
          • guy038G
            guy038
            last edited by

            Hello @chuck-ballinger,

            An other possibility is to use regular expressions !

            Let’s suppose that you want to insert a X character, in column n, on any line of your file :

            • Open the Replace dialog ( Ctrl + H )

            • OPTIONS Wrap around and Regular expression checked

            • SEARCH (?-s)^.{n-1}\K\x20+(?=(X))|^.{0,n-1}\K ( Replace the expression n-1 with the appropriate number ! )

            • REPLACE ?1:n spacesX

            • ACTION click TWICE on the Replace All button

            So, assuming the initial text, below, with a first blank line :

            
            1
            12
            123
            1234
            12345
            123456
            1234567
            12345678
            123456789
            1234567890
            12345678901
            123456789012
            1234567890123
            12345678901234
            123456789012345
            

            After two click on Replace All, we get the text :

                     X
            1        X
            12       X
            123      X
            1234     X
            12345    X
            123456   X
            1234567  X
            12345678 X
            123456789X
            123456789X0
            123456789X01
            123456789X012
            123456789X0123
            123456789X01234
            123456789X012345
            

            If you like that solution, I’ll give you, next time, some details on that regex S/R !

            Best Regards,

            guy038

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