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

-
Hello @petr-kurdiovský,
From your picture, the last
0, in line3, seems at position21, not 20 ?Anyway, here is one method :
-
Firstly, you could use the column mode feature to catch your column of numbers, in your
xRENfile and copy this selection -
Secondly, paste this rectangular selection, in line
3, at column20( or21! ) of yourxCOMfile -
Thirdly, if
Lrepresents the identical number of chars of each line :-
Select your
xCOMfile -
Open the Replace dialog (
Ctrl + H) -
SEARCH
(?-s)^.{L}\K\x20+( Of course, replace the literal valueLwith a number110,115,120, … ) -
REPLACE
Leave EMPTY -
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click, exclusively, on the
Replace Allbutton
-
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,
guy038
-
-
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

-
Hi, @petr-kurdiovský, and All,
Ah, OK ! I assumed that you wanted to populate your
xCOMfile, 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
Sspace characters AFTER columnC, included. Then use the following generic regex S/R :SEARCH
(?-s)^.{C}\K\x20+SEARCH
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20Remark : Unfortunately, in replacement regexes, you cannot use the syntax
\x20{S}, where S =10in your case. But, instead of writing10times the\x20syntax, you may, of course just type in tenspacechars, with theSpacekey, 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
Llength !Cheers,
guy038
-
-
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.