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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • 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 Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top