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
xREN
file and copy this selection -
Secondly, paste this rectangular selection, in line
3
, at column20
( or21
! ) of yourxCOM
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 valueL
with a number110
,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,
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
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 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\x20
Remark : Unfortunately, in replacement regexes, you cannot use the syntax
\x20{S}
, where S =10
in your case. But, instead of writing10
times the\x20
syntax, you may, of course just type in tenspace
chars, with theSpace
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 !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.