Batch replace specific line #s in an xml with specific text (lines) from a 2nd xml file in Windows 7

0

First of, I'm not a Coder or Unix guy, I'm using notepad++ v6.18 on Win7, so I'd ask that you "dumb it down" for me please :)

I've noticed that on the left side of each line within a notepad++ file there are numbers in "gray" , indicating the corresponding line number, so I thought the "Find & Replace" feature would be straight-fwd (i.e replace line 17 in file 1 with line 2 in file 2) wouldn't that be nice!!! Well, I was wrong and I can't seem to find a way to achieve what I'm trying to do...

I have 2 txt (or xml files) f1 & f2 and what I'm trying to do is here is replace certain lines within f1 with a given line in f2...

And here is an example...

file 1 (with several hundred lines)

(item)(title)ABC(/title)(link)a_bunch_of_code(/link)(/item)

(item)(title)XYZ(/title)(link)a_different_code(/link)(/item)

etc...

file 2 (each line has a different code)

hkskskdnnkk

absvdhvskkcncl

etc...

And what I want to do is... replace line 1 in file 1 with line 2 of file 2 then replace line 2 in file 1 with line 1 in file 2 etc...So ideally I'm thinking of some command or script that says...find line 1 in file 1 and replace it with line 2 in file 2 then find line 2 in file 1 and replace it with line 1 in file 2 etc...

Maybe this has to be done outside Notepad++ using a 3rd party tool or something...Please advise and thank you in advance! -Paul

Paul M

Posted 2012-11-11T09:26:28.407

Reputation: 31

To reply to users, add a comment below, please don't edit their posts. Thanks! – slhck – 2012-11-11T18:36:05.847

Answers

0

Depending on the scope of replacement, you have two approaches:

  1. Install plug-in manager for Notepad++ and Compare plug-in, it's great for comparing contents of two files. If you just want to replace some text (one or more words) with other text, you can do it manually by using search and replace in Notepad++. That's suitable solution if you have small number of such texts or if text to be replaced is short.

  2. If number of such replacements is high, and if you need to do such replacements often, then you need something like Unix diff and patch, and there are lot of such tools for free for Windows. Usage is simple - output of diff tool is a patch file which you can apply (with patch tool) to second file to get both files the same. Simpler is to copy file, but if you do not want whole files to be identical, but only some lines, edit patch file (it's plain text file) and just remove what you don't need.

stemd

Posted 2012-11-11T09:26:28.407

Reputation: 386

Option 2 maybe the way to go...although I think comparing the 2 files may not help all that much coz the 2nd file only has nothing in common at all with the 1st. All I'm trying to do is port 100s of lines from the 2nd file to the 1st, as described above. Can you recommend any tools for windows to help me achieve that? THX – Paul M – 2012-11-12T16:37:44.090