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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:32:32+00:00 2026-06-10T21:32:32+00:00

What I want to do is, diff 2 files and write the diff output

  • 0

What I want to do is, diff 2 files and write the diff output to 3 different files.
I can tell diff to format its output like:

diff a.txt b.txt --new-line-format=... --old-line-format=... --unchanged-line-format=...

And using this:

diff a.txt b.txt --new-bla-bla="echo %l>new.txt" --old--="echo %l>old" ...

I can output to 3 different files, except the double quotes don’t appear.
I want to do this as minimally as possible, so running 3 diffs, etc are not an option

  • 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-10T21:32:34+00:00Added an answer on June 10, 2026 at 9:32 pm

    Here’s a solution that is maybe a little longer, but more robust as it avoids the need for eval:

    diff a.txt b.txt --new-line-format "3 %L" \
                     --old-line-format "4 %L"\
                     --unchanged-line-format "5 %L" |\
       while read -r fd line; do
         echo "$line" >&$fd
       done 3> new.txt 4> old.txt 5> unchanged.txt
    

    This works by prefixing each of the new, old, and unchanged lines (respectively) with the file descriptor of the file we will add them to. We then parse the output using read, and echo the line to the correct file descriptor, each of which is redirected to the correct output file.

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

Sidebar

Related Questions

I want a diff output like - old line 1 + new line 1
So the utility Diff works just like I want for 2 files, but I
In python I want to diff two files using commands.getoutput('diff a.txt b.txt') and if
I'd like to use diff Unix command to compare between output files. However ,
I have a file called diff.txt . I Want to check whether it is
There's another question: howto make diff look like svn diff? but I want the
I do something like svn diff > /mystuff/current.diff. I want to view this .diff
How can I diff two files and ignore lines starting with a sequence. E.g
Basically, what I want is git diff HEAD branch1 -- foo.txt > patch.txt; git
How can you diff two pipelines without using temporary files in Bash? Say you

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.