Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

Merge 2 text files into one, same lines

I have one file and contains:

file2.txt

PRIMERB
PrinceValiant
Priory
PRISTINA
embossed
heavy
incised
light
Outline
ribbon

and

file1.txt

PRIMERB 333
PrinceValiant 581
Priory789
PRISTINA3!1
embossed509
heavy5@
incised999
light5*1
Outline937
ribbon-81

I'd like to combine/merge these two files together so they would be like :

PRIMERB 333 PRIMERB
PrinceValiant 581 PrinceValiant
Priory789 Priory
PRISTINA3!1 PISTINA
embossed509 embossed
heavy5@ heavy
incised999 incised
light5*1 light
Outline937 Outline
ribbon-81 ribbon

How would I do this in ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Add space characters to the end of the first line of file1 until it is longer than the longest line in file1.

  2. Do a column mode selection of the entire contents of file 2. Do this by holding the ALT key down while dragging the mouse across the file. As you drag you should see a rectangular area of the screen selected. It may be easiest to start the selection before the first character in the first line of file2. Could also do a column mode selection with just the keyboard. Hold the ALT and Shift keys down while moving the cursor with the arrow keys.

  3. Copy the selected text. (Control-C or menu => Edit => Copy or context menu => copy.)

  4. Paste after the spaces added to file1.

  5. Remove unnecessary spaces.

If the existing spaces in files1 and file2 are important you might use a regular expression to alter every line in file2 to have some character or character sequence that does not occur in either file before selecting its contents. For example, find ^ and replace with !!. Then you can use another regular expression to remove only the spaces added by the paste. For example, replace _*!! (space, asterisk, exclamation-mark, exclamation-mark) with _ (space; note that spaces would show incorrectly in these two strings, so they are shown as underscores _ for clarity).

See also the Editing => Column mode editing section of the Notepad++ help pages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...