LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to retrieve the text difference between two strings having substrings (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-retrieve-the-text-difference-between-two-strings-having-substrings-879884/)

pklcnu 05-10-2011 02:18 PM

How to retrieve the text difference between two strings having substrings
 
Dear Experts

I got requirement to find the difference between two strings and write the difference to new file by comparing the substrings separted by commas

Below mentioned is an example of requirement

String1 --> ABC,DEF,GHI,JKL
String2 --> MNO,ABC,XYZ,DEF

In String1 and String2 the substrings are separted by commas. The substrings which are common between String1 and String2 are ABC,DEF this common substrings has to be written to a file say common.txt ( having the text ABC,DEF). And the substrings GHI,JKL in String1 which are not present in String2 has to be written to another file say String1Extra.txt (having the text GHI,JKL). In the same way the substrings MNO,XYZ from String2 which are not present in String1 has to be written to another file say String2Extras.txt(having the text MNO,XYZ) .

How to achieve this ?

Many thanks in advance for your help

TB0ne 05-10-2011 03:35 PM

Quote:

Originally Posted by pklcnu (Post 4352294)
Dear Experts
I got requirement to find the difference between two strings and write the difference to new file by comparing the substrings separted by commas Below mentioned is an example of requirement

String1 --> ABC,DEF,GHI,JKL
String2 --> MNO,ABC,XYZ,DEF

In String1 and String2 the substrings are separted by commas. The substrings which are common between String1 and String2 are ABC,DEF this common substrings has to be written to a file say common.txt ( having the text ABC,DEF). And the substrings GHI,JKL in String1 which are not present in String2 has to be written to another file say String1Extra.txt (having the text GHI,JKL). In the same way the substrings MNO,XYZ from String2 which are not present in String1 has to be written to another file say String2Extras.txt(having the text MNO,XYZ) .

How to achieve this ?
Many thanks in advance for your help

This sounds VERY much like homework.

What have you tried/done thus far?? What programming language are you using? The methods of doing this differ between bash, perl, ruby, etc., so what is your 'requirement' for the language?


All times are GMT -5. The time now is 08:39 PM.