Merge txt files and remove duplicate lines

Kyuft

Member
Reaction score
11
Hey,
I have two files that i want to merge. I want to merge 1.txt and 2.txt, however they have duplicate lines, and I want those to be removed. Can anyone guide me in making a batch file that will merge those files into 1 file and remove the duplicate lines? (I have no experience with batch)

-Kyuft:shades:

EDIT: Solved using TextPipe
 

camelCase

The Case of the Mysterious Camel.
Reaction score
362
You can do that with batch files? ;O
I always thought that was only feasible with perl or something similar =x

Is there any particular order you need the lines to be in when merged?
 

Kyuft

Member
Reaction score
11
There is no particular order that the lines need to be in. I was hoping this could be done in batch, but if you can do it any other way, I would greatly appreciate it. I just don't want to have to download special software to run the code (unless, of course, the solution is a software that you coded).

-Kyuft:shades:
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
I know you said you solved this, but I just wanted to mention some things.

I assume this might be related to localization issues in SC2? I had a similar problem a while ago with Cruiser Command. There are some people interested in translating Cruiser Command to Chinese and publishing it on the chinese servers. So I told them how to extract the game strings, and then how to import it back into the map.

However when I give them a new version, I don't want them to have to re-translate everything. I created a program that basically goes through the new text file and checks if that key exists in the old translated file. If it does, it appends the translated row into the new merged document. If it doesn't exist in the old translated file, it takes the row from the new file and appends it in the merged document. It also alerts the user of any new rows that appear in the new document but not in the old so the translator doesn't have to search through thousands of rows to find the new rows.

I've done some basic testing with it and it seems to work. It should work with your map as well even if you're probably working with two english versions.

Here's the code. It's written in Python 2.7.2 but any 2.x version should work. I know you mentioned not wanting to download any extra software, but Python is awesome and nice for learning how to program.
Code:
print "Siretu's Text Merge Program"
print "Please put the old and new text files in the same folder as this program."
old = open(raw_input("Enter the name of the OLD text file. This is the one that contains all the translations: ")).read().split("\n")
new = open(raw_input("Enter the name of the NEW text file. This is the one that contains all the english strings: ")).read().split("\n")
merge = []

for s in new:
    if s:
        notFound = True
        key = s.split("=")[0]
        value = s.split("=")[1]
        for i in old:
            if i:
                key2 = i.split("=")[0]
                value2 = i.split("=")[1]
                if key == key2:
                    notFound = False
                    merge.append(key+"="+value2)
                    break
    if notFound:
        print "Found new key! Make sure you translate "+key
        merge.append(key+"="+value)

f = open("GameStringsMERGED.txt","w")
f.write("\n".join(merge))
f.close()
 

Kyuft

Member
Reaction score
11
Well, I do want to learn how to program, and Python looks relatively simple, how would I go about learning Python code? Where should I start?

-Kyuft:shades:
 

Kyuft

Member
Reaction score
11
Are there advanced tutorials somewhere for when I'm done with the beginner ones?

-Kyuft:shades:
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
Dive into python goes into some of the more advanced areas. When you're done with that, you just have to think of something you want to learn and search for it. You should be able to find a tutorial on it pretty easily.
 

Kyuft

Member
Reaction score
11
Okay, I'm done with the beginner stuff, and its REALLY simple. I like it! :) One question about your program though. If I run this program on my files would it work? My old files has almost all of the trigger stuff, and the new file is mostly data. Therefore, there is new stuff in both files.

-Kyuft:shades:
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
Yes, it should work anyway.

Since my program doesn't modify the original files, you could just try it out. You'll get a merged file in the same directory. Search for a string that is only in the first file and search for another one that is only in the second file. If you find both in the merged file, chances are that it worked.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top