please:
seemed to me it was a trivial task but after few hours i need help...
how do I compare two lists and report found on list 2 without the use of formatlist sort/dedupe?
IOW it is important to keep the original sequence of occurrences in the final report.
list 1:
some stuff.txt
unsorted stuff.txt
neutral stuff.txt
list 2:
tasks to do.txt
some stuff.txt
readme.txt
reqs.txt
neutral stuff.txt
seen.txt
correct answer:
some stuff.txt
neutral stuff.txt
Help with lists
-
highend
- Posts: 14955
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Help with lists
Compare each entry in the left list with each entry in the right list and when a match is found, remove it from the right list.
Like this:
some stuff.txt
Compared with:
tasks to do.txt
some stuff.txt
readme.txt
reqs.txt
neutral stuff.txt
seen.txt
some stuff.txt is found, remove if from the right list and continue with unsorted stuff.txt from the left list.
it's only a foreach() with gettoken in the left listand a bit of regexereplace / replace in the right list.
Like this:
some stuff.txt
Compared with:
tasks to do.txt
some stuff.txt
readme.txt
reqs.txt
neutral stuff.txt
seen.txt
some stuff.txt is found, remove if from the right list and continue with unsorted stuff.txt from the left list.
it's only a foreach() with gettoken in the left listand a bit of regexereplace / replace in the right list.
One of my scripts helped you out? Please donate via Paypal
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: Help with lists
I don't know if i understand what you want to do, or where this lists came from.
But something like this should give you an idea:
HTH?
.
But something like this should give you an idea:
Code: Select all
$list1 = "some stuff.txt<crlf>
unsorted stuff.txt<crlf>
neutral stuff.txt";
$list2 = "tasks to do.txt<crlf>
some stuff.txt<crlf>
readme.txt<crlf>
reqs.txt<crlf>
neutral stuff.txt<crlf>
seen.txt";
$out="";
foreach($line, $list2, "<crlf>"){
//IF $line from $list2 is found in $list1, i get an position start index equal or greater zero:
if ( strpos($list1, $line, ,1) >= 0 ){ $out = "$out$line<crlf>"; }
}
// If wanted, some cosmetic: remove last added CRLF:
$out = replace($out, "<crlf>", "", ,strlen($out)-5);
msg $out;
/*
Output:
---------------------------
XYplorer
---------------------------
some stuff.txt
neutral stuff.txt
---------------------------
OK
---------------------------
*/
HTH?
.
-
neutrox
- Posts: 194
- Joined: 05 Mar 2012 15:23
Re: Help with lists
i have to understand quick that strpos thingie lol
many thanks to Stefan and highend that helped me a lot with this and other post
many thanks to Stefan and highend that helped me a lot with this and other post
-
neutrox
- Posts: 194
- Joined: 05 Mar 2012 15:23
Re: Help with lists
hope i'm not being abusive but is there a way for the script to to not output duplicated entries? I mean... if a string is found once, it being not reported a second time?
again, without the use of formatlist sort/dedupe as duplicates may not be immediate neighbors?
again, without the use of formatlist sort/dedupe as duplicates may not be immediate neighbors?
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: Help with lists
Nema problemo.neutrox wrote:hope i'm not being abusive but is there a way for the script to to not output duplicated entries?
I mean... if a string is found once, it being not reported a second time?
again, without the use of formatlist sort/dedupe as duplicates may not be immediate neighbors?
It's a pity that formatlist dedupe works only on sorted lists.
// $out = formatlist($out, "d", "<crlf>");
// $out = formatlist($out, "sd", "<crlf>");
but we can do it ourself the same way as we did it above.... with the aid of strpos()
Code: Select all
$list1 = "some stuff.txt<crlf>
unsorted stuff.txt<crlf>
neutral stuff.txt";
$list2 = "tasks to do.txt<crlf>
some stuff.txt<crlf>
readme.txt<crlf>
reqs.txt<crlf>
some stuff.txt<crlf>
neutral stuff.txt<crlf>
some stuff.txt<crlf>
seen.txt";
$out="";
foreach($line, $list2, "<crlf>"){
if ( strpos($list1, $line, ,1) >= 0 ){
//Add only if not already in $out:
if ( strpos($out, $line, ,1) == -1 ){
$out = "$out$line<crlf>"; }
}
}
$out = replace($out, "<crlf>", "", ,strlen($out)-5);
msg $out;
-
neutrox
- Posts: 194
- Joined: 05 Mar 2012 15:23
Re: Help with lists
ive put a foreach (list 1) inside a foreach (list 2) inside a foreach (l1 == l2) { l3 against l1 or l2 },
then completely reversed the logics behind lists comparison just to end in the boondocks again
couldn't do without your help, guys!
then completely reversed the logics behind lists comparison just to end in the boondocks again
couldn't do without your help, guys!
XYplorer Beta Club