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 8226727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:52:27+00:00 2026-06-07T15:52:27+00:00

Is it possible to create a diff patchfile that will edit lines themselves, rather

  • 0

Is it possible to create a diff patchfile that will edit lines themselves, rather than replacing an entire line?

For example, I have the following line:

 <foo:ListeningPortBar>3423</foo:ListeningPortBar>

and I want to change this to:

 <cat:LoremIpsum>3423</cat:LoremIpsum>

That is, I want to change the text around the actual port number, but preserve the port number – I need to apply this patch across a number of files, all with different port numbers – I simply want to change the tags, keeping whatever port number is in there currently.

How can you achieve this please?

Thanks,
Victor

  • 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-07T15:52:28+00:00Added an answer on June 7, 2026 at 3:52 pm

    It doesn’t really matter if a patch replaces the entire line or just characters in the line (the end result is the same, no…?), but I don’t think this is a “patch” question. See below for a simpler solution using “sed”.

    For example, assume:

    $ cat f1.txt
    <xml>
    <foo:ListeningPortBar>3423</foo:ListeningPortBar>
    </xml>
    
    $cat f2.txt
    <xml>
    <cat:LoremIpsum>3423</cat:LoremIpsum>
    </xml>
    

    Then, literally the patch would be:

    $ diff -u f1.txt f2.txt
    --- f1.txt  2012-07-08 03:14:39.328328048 -0700
    +++ f2.txt  2012-07-08 03:14:30.618177130 -0700
    @@ -1,3 +1,3 @@
     <xml>
    -<foo:ListeningPortBar>3423</foo:ListeningPortBar>
    +<cat:LoremIpsum>3423</cat:LoremIpsum>
     </xml>
    

    This patch file could be used as a template, modified with correct values for all your files that need to be updated, and applied to all the files individually. That sounds like more work than necessary.

    On the other hand, just use “sed”:

    $ sed 's/<foo:ListeningPortBar>\([0-9]*\)<\/foo:ListeningPortBar>/<cat:LoremIpsum>\1<\/cat:LoremIpsum>/' f1.txt  
    <xml>
    <cat:LoremIpsum>3423</cat:LoremIpsum>
    </xml>
    

    Since you have XML, using xsltproc is another alternative, but again probably overkill for this simple search-and-replace task.

    To use this in a script, you’d do something like (replacing “etc/etc” with the sed above):

    for f in $(find dir -name "*.xml" -exec egrep 'foo:ListeningPortBar' {} \; -print)
    do
      sed -i.bak 's/etc/etc/g' $f
    done
    

    …and then verify that the “.bak” files are actually different than the modified files.

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

Sidebar

Related Questions

Is it possible to create an SSIS package that can be passed a file
is that possible create an abstract class from DbQuery and IDbSet? I'm trying to
Possible Duplicate: Create a date with T-SQL I've a data table that stores each
I want to create an application that will automate a very specific build process
Possible Duplicate: Create a variable in .CSS file for use within that .CSS file
Is possible create an extension for SQL Management Studio in Visual Studio 2010? Visual
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create provisioning profile in iphone application i developed my iphone app and
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am

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.