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

  • Home
  • SEARCH
  • 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 8032859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:31:19+00:00 2026-06-05T01:31:19+00:00

Possible Duplicate: How can I replace lines in a text file with lines from

  • 0

Possible Duplicate:
How can I replace lines in a text file with lines from another file based on matching key fields?

I want to merge the following files and I want the contents of FileB.txt to overwrite FileA.txt where there are common lines, but I don’t want to completely replace FileA.txt with FileB.txt.

For example:

File A:

# cat FileA.txt 
interface.1.type = ethernet
interface.1 = A
interface.1.ip = 192.168.1.1
interface.1.netmask = 255.255.255.0
interface.1.dhcp = false

File B:

# cat FileB.txt 
interface.1 = B
interface.1.ip = 192.168.1.1
interface.1.netmask = 
interface.1.dhcp = true
interface.1.dhcp.range = 192.168.1.1,192.168.1.15
interface.1.extraline =

In this case
The merge result should be:

# cat FileA.txt
interface.1.type = ethernet
interface.1 = B
interface.1.ip = 192.168.1.1
interface.1.netmask = 
interface.1.dhcp = true
interface.1.dhcp.range = 192.168.1.1,192.168.1.15
interface.1.extraline =

So anything before the ‘=’ on each line should be checked and matched between FileA.txt and FileB.txt. If any after the ‘=’ on FileB.txt differs from FileA.txt then whatever is in FileB.txt should be written to FileA.txt.

  • 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-05T01:31:21+00:00Added an answer on June 5, 2026 at 1:31 am

    Try this sort command:

    sort -t= -k1,1 -us FileB.txt FileA.txt
    

    -t=: split the lines into fields on the ‘=’, so you are sorting on the keys

    -k1,1: sort on the first field. This is important, as duplication (see below) depends
    only on the specified sort field.

    -u: eliminate duplicates. If two lines have the same key, only the first is kept.

    -s: stable sort. If two lines are identical based on their sort field, the line that
    is seen first in the input remains first in the output.

    By putting FileB.txt in the list of input files first, you ensure that the line from
    FileB.txt is chosen over the line from FileA.txt if they share the same key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to edit a file in Vim with all lines ending in
Possible Duplicate: How to programatically build and compile another c# project from the current
Possible Duplicate: vim: search replace over all writable buffers I can use :%s/foo/blah/g to
Possible Duplicate: PHP: Strip a specific tag from HTML string? Hi All, I want
Possible Duplicate: RegEx match open tags except XHTML self-contained tags how can I replace
Possible Duplicate: Replace Div with another Div <div id='test'> <span></span> <p></p> <button></button> <h1></h1> </div>
Possible Duplicate: Can we solve the table row background image problem, in chrome, in
Possible Duplicate: Can I use operators as function callback in PHP? Is it possible
Possible Duplicate: Can I retrieve an ipad unique device identifier that through Safari with
Possible Duplicate: Can we post image on twitter using twitter API in Android? I

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.