-1

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

 test1.txt
 1
 2

 test2.txt
 1
 2
 3
 4 

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.

2
  • 1
    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, 2012 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, 2012 at 11:01

1 Answer 1

1

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
3
  • diff test2.txt test1.txt > test.patch patch **test.txt** < test.patch i patch the result into a third file
    – HardCode
    Aug 13, 2012 at 11:20
  • The issue is with CSV files. TXT files work well
    – HardCode
    Aug 13, 2012 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, 2012 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .