Replace data on specific position by data from 2nd file

  • Hello everyone, can you help me with special task.
    I have two files. I need to get data on each line on file1 and put it to same line in file2.
    Source data have variable length.
    On target file first character starting on same position on every line -position 20.
    Its necessary to keep total number of characters on every line.
    Please see attached picture. Lines 3, 4 and 5 are edited manual.
    Is there any chance to create automatic process for this task?
    Thanks Petr
    replace characters  on line.JPG

  • Hello @petr-kurdiovský,

    From your picture, the last 0, in line 3, seems at position 21, not 20 ?

    Anyway, here is one method :

    • Firstly, you could use the column mode feature to catch your column of numbers, in your xREN file and copy this selection

    • Secondly, paste this rectangular selection, in line 3, at column 20 ( or 21 ! ) of your xCOM file

    • Thirdly, if L represents the identical number of chars of each line :

      • Select your xCOM file

      • Open the Replace dialog ( Ctrl + H )

      • SEARCH (?-s)^.{L}\K\x20+ ( Of course, replace the literal value L with a number 110, 115, 120, … )

      • REPLACE Leave EMPTY

      • Tick the Wrap around option

      • Select the Regular expression search mode

      • Click, exclusively, on the Replace All button

    Et voilà !

    Remark : The nice thing is you could paste a lost of columns ( rectangular selections ) and, only at the end, perform the regex S/R !

    Best Regards,


  • Thanks Mr. guy038
    Your guide works perfect.
    Best Regards Petr

  • Hello, I found another problem.
    In case the target file already have data in another column /for example on position 31/ the format of file is corrupted because I remove extra spaces on end of line.
    I need remove spaces on right side 31 position.
    Thanks Petr
    replace characters  on line2.JPG

  • Hi, @petr-kurdiovský, and All,

    Ah, OK ! I assumed that you wanted to populate your xCOM file, with columns from the leftmost till the rightmost !

    If you don’t respect that order, here is a … regex solution, again ! Let’s suppose you always need S space characters AFTER  column C, included. Then use the following generic regex S/R :

    SEARCH (?-s)^.{C}\K\x20+

    SEARCH \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20

    Remark : Unfortunately, in replacement regexes, you cannot use the syntax \x20{S}, where S = 10 in your case. But, instead of writing 10 times the \x20 syntax, you may, of course just type in ten space chars, with the Space key, in the replacement zone !

    Finally, don’t forget to perform my previous regex S/R to normalize all the lines of your table to their common L length !



  • Hi Mr. guy038
    I guess I’m doing something wrong.
    Here is link to my files :link text
    In the file X.COM are two lines like heather
    and next 3 lines edited manual -this is correct format I need.
    Please, can you check if its working?
    Thanks Petr

  • Hi all, I found solution!
    1.Add 10 spaces at end of each lines in file X.REN by command $
    2.Copy rectangular selection 10 x number of lines in file X.REN
    3.Mark rectangular selection 10 x number of lines on target file in requested position and paste it.

Log in to reply