Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:24:55+00:00 2026-06-06T05:24:55+00:00

I have two text files with various columns, each column is separated by a

  • 0

I have two text files with various columns, each column is separated by a tab (” “). What I’m trying to do is the following:-

  • If the values in text file 2 column 1 does not contain any value in text file 1 column 1 then add that field to text file 2 and add a 1 to the second column, like so

    String 1

  • If the value in text file 2 column 1 already appears in text file 1 columns 1 then just add +1 to the value, so if the above value is already in Text File 1 Column 1 and Text File 2 Column 1 then it would appear as.

    String 2

And if it was to happen again then

String 3

and so on.

I have the following coding so far.

Dim lines1 As New List(Of String)(IO.File.ReadAllLines("File1"))
Dim lines2 As New List(Of String)(IO.File.ReadAllLines("File2"))
IO.File.WriteAllLines("File2", lines1.ToArray) & +1)

Update

Dim lines1 As New List(Of String)(IO.File.ReadAllLines("D:\Test\File6.txt"))
        Dim lines2 As New List(Of String)(IO.File.ReadAllLines("D:\Test\File5.txt"))

        Dim values As New Dictionary(Of String, Integer)()
        For Each line As String In lines1
            Dim fields() As String = line.Split(" "c)
            If fields.Length > 1 Then
                values(fields(0)) = Integer.Parse(fields(1))
            End If
        Next

        For Each line As String In lines2
            Dim fields() As String = line.Split(" "c)
            If fields.Length > 0 Then
                If values.ContainsKey(fields(0)) Then
                    values(fields(0)) = values(fields(0)) + 1
                Else
                    values(fields(0)) = 1
                End If
            End If
        Next

        lines1.Clear()
        For Each pair As KeyValuePair(Of String, Integer) In values
            lines1.Add(pair.Key + " " + pair.Value.ToString())
        Next

        IO.File.WriteAllLines("D:\Test\File6.txt", lines1.ToArray)

I use the above coding, but it removes the second column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:24:57+00:00Added an answer on June 6, 2026 at 5:24 am

    I would recommend using a dictionary to store the key/value pairs in your first text file. Then, you can easily search and modify the data in the dictionary as you parse the data in the second text file. For instance:

    Dim lines1 As New List(Of String)(New String() {"A a 1", "B b 2", "C c 3"})
    Dim lines2 As New List(Of String)(New String() {"A a", "D d"})
    
    Dim values As New Dictionary(Of String, Integer)()
    For Each line As String In lines1
        Dim fields() As String = line.Split(" "c)
        If fields.Length > 2 Then
            values(fields(0) + " " + fields(1)) = Integer.Parse(fields(2))
        End If
    Next
    
    For Each line As String In lines2
        Dim fields() As String = line.Split(" "c)
        If fields.Length > 1 Then
            Dim key As String = fields(0) + " " + fields(1)
            If values.ContainsKey(key) Then
                values(key) = values(key) + 1
            Else
                values(key) = 1
            End If
        End If
    Next
    
    lines1.Clear()
    For Each pair As KeyValuePair(Of String, Integer) In values
        lines1.Add(pair.Key + " " + pair.Value.ToString())
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two 3GB text files, each file has around 80 million lines. And
I have the two following text files: First one: chr10 1000 1001 DEL 2.4807
i have two text files file 1 number,name,account id,vv,sfee,dac acc,TDID 7000,john,2,0,0,1,6 7001,elen,2,0,0,1,7 7002,sami,2,0,0,1,6 7003,mike,1,0,0,2,1
I want to append two text files together. I have one file with a
I have two text files in the following format: The first is this on
Suppose I have two text files. The first one, called reference.txt has the following
I have two text files that have these structures: File 1 Column1:Column2 Column1:Column2 ...
New to python, bear with me. I have two text files, each has a
Hi I have two text files that each contain different information about certain structures.The
I have two text files that contain columnar data of the variety position -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.