Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
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 '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

1 Answer 1

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

 
discard

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.