Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have two text files test1.txt and test2.txt with content as



what i have achieved with the txt files is a difference of both files in a third file as

diff test2.txt test1.txt > test.patch

patch test.txt < test.patch

in text.txt i have the resultant difference of both files.

Now i am doing the same with CSV files.

The format for CSV files is like

HENRY CONSTANTINE | 02256 | MEDICAL | Speciality

diff small2.csv small1.csv > small.patch

patch small.csv < small.patch

*Note: I have created the small.csv file manually.

But i get the following error when i run the patch

patching file small.csv
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file small.csv.rej

Does anyone have any idea of how to achieve the above Difference file for CSV files.

share|improve this question
This question really cannot be answered unless you post the files it applies to. You are doing the correct thing, but the it is entirely possible for a patch to fail to apply. As you show with the test.txt files, you are applying the patch to a different file than what you generated it from. Then it is possible that it doesn't apply cleanly, and you get a reject file to be able to fix it manually. – Timo Kluck Aug 13 '12 at 10:31
Thanks for editing and adding the test1.txt and test2.txt, but that doesn't help a lot because we still can't see what's failing. Can you add those too? – Timo Kluck Aug 13 '12 at 11:01
up vote 1 down vote accepted

If you want to include the file name information, use -u option:

diff -u test2.txt test1.txt > test.patch

In this case, you can use the below command:

patch -o test.txt < test.patch

If you return to the original contents, you can use the below command:

patch -R test.txt < test.patch
share|improve this answer
diff test2.txt test1.txt > test.patch patch **test.txt** < test.patch i patch the result into a third file – HardCode Aug 13 '12 at 11:20
The issue is with CSV files. TXT files work well – HardCode Aug 13 '12 at 11:32
Can't it do by the same way? diff -u small2.csv small1.csv > small.patch and patch -o small.csv < small.patch . – vine_user Aug 13 '12 at 11:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.