Clean list of strings that are included on the own strings
bash, list, python, shell, string
Solution
If I understand your question correctly, you want to take a list of strings and remove from it any strings that are substrings of other strings in the list.
In pseudo-code,
outer: for string s in l
for string s2 in l
if s substringOf s2
continue outer
print s
i.e. loop through the strings once for every string, canceling each run of the outer loop if any of the tests in its inner loop matches.
Here's an implementation of that algorithm in bash. Note that the file (`list.txt`) is being read through the redirection operator `<` twice in the code, once for the outer loop and once for the inner.
(I've also cleaned up your example, which had a lot of typos.)
$ cat list.txt
HI family what are u doin?
HI family what are
Channel 5 is very cheap
Channel 5 is
Channel 5 is very
Pokemon
The best Pokemon is Pikachu
$ while read line; do while read line2; do [[ $line2 != $line ]] && [[ $line2 == *$line* ]] && continue 2; done <list.txt; echo "$line"; done <list.txt
HI family what are u doin?
Channel 5 is very cheap
The best Pokemon is Pikachu
$
Problem
I have a text-file, `lists.txt`, that looks like this: ``` HI family what are u doing ? HI Family what are Channel 5 is very cheap Channel 5 is Channel 5 is very Pokemon The best Pokemon is Pikachu ``` I want to clean it up, removing any lines that are completely included inside other lines. That is, I want something like this: ``` HI family, what are u doing ? The best Pokemon is Pikachu Channel 5 is very cheap ``` I have try with count the large of the strings and later comparate its with grep, finding the sorts results.txt on large results.txt, but it's little effective.