Pasting only onto lines displayed with filter

Pasting only onto lines displayed with filter

3
NewbieNewbie
3

    14:55 - Jan 22#1

    I have a file that I need to change about 1000 lines out of (that are unfortunately not all in sequence due to how the file is set up) where I need to paste a string of characters to a certain column on those line. Unfortunately each line (while starting with the same characters) is different, so I can't (that I know of) easily just do a Find->Replace. I can easily filter to just those lines and then hit the down arrow and CTL+V 1000+ times, but I'm hoping there's a much quicker/easier way to do it. But I'm not seeing a 'Paste only on visible lines' option, and if I just select the whole column in column mode and paste, it pastes to every line and not just the visible ones. 

    Is there a way to do what I'm wanting to, or do I just need to suck it up and do it manually? Thanks!

    6,675585
    Grand MasterGrand Master
    6,675585

      17:06 - Jan 22#2

      There is no possibility to paste only on visible lines to change something on those lines while keeping the currently hidden lines unmodified.

      But if the same change must be done on all currently visible lines, it should be no problem running a regular expression find and replace to change the data wherever existing on the visible lines. I recommend reading the power tips tagged regular expression (UltraEdit regular expression engine) and Perl regular expression using backreferences (most powerful Perl regular expression engine).

      Post a reply with about 10 lines copied from the file if you need help on the search/replace expression. The block should be formatted as preformatted text using the last but one symbol on the toolbar above the edit area. This block should contain some lines to modify and also some lines between to keep as is. The post should contain also a second block showing us how the first block should look like after the regular expression find and replace with the changes made by you manually in this block. Please explain also how to identify the lines to modify (visible lines) and which part in these lines should be modified with a regular expression find and replace.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        17:43 - Jan 22#3

        Thanks, I'll read those tips for the next time this comes up (I went through and did it manually since it's something I needed to get done ASAP), but it's something I'd like to have in my pocket for the future since I expect this will come up again. Unfortunately I can't paste the actual data here since it's for work and pretty restricted, but if I get the chance I'll make up a similar bunch of lines to show what I'm looking to do and post.

        19176
        MasterMaster
        19176

          10:39 - Jan 23#4

          Hi Ashyukun,

          I suppose there are the same characters at the beginning of each line you want to change. If the column number in all such lines is same then you should be able to write a simple perl regexp Find/Replace regardless how much you know about regexes.

          Find: ^starting_characters.{count_of_skipped_characters}\K
          Replace:  paste_string

          For example all searched lines start with This is the line to be changed and you want to paste text My clipboard at column 100. In this case the length of the fixed part is 30 so you must skip next 70 characters to get to the column 100.
          Just keep in mind that some searching characters have special meaning and must be written as \<special_char> - e.g. \?, \[, \\, \*, \+, \{, \^ etc (see any perl regexp tutorial for more information)

          F: ^This is the line to be changed.{70}\K
          R: My clipboard

          I hope this will help you to solve your problem.
          Fleggy

          3
          NewbieNewbie
          3

            18:21 - Jan 23#5

            Actually (at least in this particular case), I needed to keep most of the line the same and just append some characters to the end of (most of) the lines that started in a particular string. Here's an example section of the file (a NASTRAN bulk data input file) similar to what I was working with:

            Code: Select all

            $ Start of bar element definition
            PBAR     20    100       0.75
            CBAR     20    20        100     101     0.      1.      0.
            CBAR     21    20        101     102     0.      1.      0.
            CBAR     22    20        102     103     0.      1.      0.
            PBAR     30    100       0.525
            CBAR     30    30        200     201     0.      1.      0.
            CBAR     31    30        201     202     0.      1.      0.
            PBAR     40    100       0.475
            CBAR     40    40        400     401     0.      1.      0.
            CBAR     41    40        401     402     0.      1.      0.
            CBAR     42    40        402     403     0.      1.      0.
            CBAR     43    40        403     404     0.      1.      0.
            PBAR     50    100       0.75
            CBAR     50    50        500     501     0.      1.      0.
            CBAR     51    50        501     502     0.      1.      0.
            CBAR     52    50        502     503     0.      1.      0.
            So what needs to happen is that for every line that starts with PBAR, I need to append two more values to the end of it (in practice, it needed to be 'for every line that starts with PBAR and does not already have data in the two columns that will be potentially added', but that's easy enough to work around since those instances were pretty rare) while keeping everything before where the new data was added the same. The end state would be as follows:

            Code: Select all

            $ Start of bar element definition
            PBAR     20    100       0.75    0.025   0.025 
            CBAR     20    20        100     101     0.      1.      0.
            CBAR     21    20        101     102     0.      1.      0.
            CBAR     22    20        102     103     0.      1.      0.
            PBAR     30    100       0.525   0.025   0.025
            CBAR     30    30        200     201     0.      1.      0.
            CBAR     31    30        201     202     0.      1.      0.
            PBAR     40    100       0.475   0.025   0.025
            CBAR     40    40        400     401     0.      1.      0.
            CBAR     41    40        401     402     0.      1.      0.
            CBAR     42    40        402     403     0.      1.      0.
            CBAR     43    40        403     404     0.      1.      0.
            PBAR     50    100       0.75    0.025   0.025
            CBAR     50    50        500     501     0.      1.      0.
            CBAR     51    50        501     502     0.      1.      0.
            CBAR     52    50        502     503     0.      1.      0.
            Each PBAR line now has values (0.025 in both) in the 5th & 6th data columns (NASTRAN uses eight character columns). Oh, and the new data always needs to start in the same column (33) regardless of where the existing line already ends (since the value in the 4th column isn't always the same length).

            19176
            MasterMaster
            19176

              21:03 - Jan 23#6

              Hi,

              Because there is no feature to count characters inside the string matched by a Perl regular expression you must consider the worst case when the third column is only one character long so the first added value 0.025 must be preceded by seven spaces. Then the second regexp replace removes the extra spaces.
              1. Replace All to append the missing values
                Find: ^PBAR(?: +[0-9.]+){3}$
                Replace: $&       0.025   0.025
                 
              2. Replace All to align the appended values to column 33
                Find: ^PBAR.{29}\K +
                Replace: leave it empty
              Tested on your sample (no spaces after the last digit/dot in the third column in PBAR lines) and the result looks okay to me.
              BR, Fleggy