What is a shell command to find the longest common substring of two strings in unix? like: foo 'abcdefghi' 'abjklmdefnop' prints: def
相关问题
- How to get the return code of a shell script in lu
- how to split a list into a given number of sub-lis
- Is shmid returned by shmget() unique across proces
- Generate string from integer with arbitrary base i
- how to get running process information in java?
This is known as the longest common subsequence problem and there are some great algorithms for it. Check out the dynamic programming solution (If you google it, you'll find a ton of implementations). If you really want to understand this at an algorithmic level, check out this MIT lecture,
http://videolectures.net/mit6046jf05_leiserson_lec15/
I am not sure if there is a single command that does the job for you but the following bash script should do it.
save the above as a file substr.sh do chmod +x substr.sh