Hi all,
I have a task to pickup the duplicated files only from the greatest versions as below
From the BEFORE list, these two files, 500298010103.S3S.mockup, 500299010103.S3S.mockup occurred in the following versions folders, 0100, 0101, and 0102 ( I used italic to marked it out)
BEFORE
\T501-03568-0100\500298010103.S3S.mockup
\T501-03568-0100\500299010103.S3S.mockup
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0101\500298010103.S3S.mockup
\T501-03568-0101\500299010103.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0102\500298010103.S3S.mockup
\T501-03568-0102\500299010103.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0102\500302010103.S3S.mockup
----------------------------------------------------------------------------------
AFTER pickup, only the greatest version of these two files have been picked up, like this case 0120, been picked up as below:
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0102\500298010103.S3S.mockup
\T501-03568-0102\500299010103.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0102\500302010103.S3S.mockup
Another thing is that we do not know which two or three.. files are duplicated in the different versions, so the above is just a example, we can not hard code these two files in the scripts
Thanks
how to pick up the duplicated files only from the greatest versions
Moderator: DosItHelp
Re: how to pick up the duplicated files only from the greatest versions
Assuming the structure of the part before the "\" is always the same (\Tnnn-nnnnn-nnnn\) :
(and assuming your list is in mockup.lst)
Output:
(and assuming your list is in mockup.lst)
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /f "usebackq delims=" %%I in (`sort mockup.lst ^| sort /R /+17`) do (
if /i "!PREVIOUS!" NEQ "%%~nI" (
echo %%I>> after.txt
set "PREVIOUS=%%~nI"
)
)
Code: Select all
\T501-03568-0102\500302010103.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0102\500299010103.S3S.mockup
\T501-03568-0102\500298010103.S3S.mockup
Last edited by Eureka! on 14 Nov 2020 11:54, edited 1 time in total.
Re: how to pick up the duplicated files only from the greatest versions
Thanks Eureka!
I tried it and is working but not the greatest version, the least version instead. The results is showing that all duplicated files have been removed but not the greatest version as expected.
\T501-03568-0100\500298010103.S3S.mockup
\T501-03568-0100\500299010103.S3S.mockup
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0102\500302010103.S3S.mockup
The expected results should looks like this
\T501-03568-0102\500298010103.S3S.mockup
\T501-03568-0102\500299010103.S3S.mockup
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0102\500302010103.S3S.mockup
I tried it and is working but not the greatest version, the least version instead. The results is showing that all duplicated files have been removed but not the greatest version as expected.
\T501-03568-0100\500298010103.S3S.mockup
\T501-03568-0100\500299010103.S3S.mockup
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0102\500302010103.S3S.mockup
The expected results should looks like this
\T501-03568-0102\500298010103.S3S.mockup
\T501-03568-0102\500299010103.S3S.mockup
\T501-03568-0100\500300010103.S3S.mockup
\T501-03568-0101\500300010104.S3S.mockup
\T501-03568-0102\500300010105.S3S.mockup
\T501-03568-0100\500302010101.S3S.mockup
\T501-03568-0101\500302010102.S3S.mockup
\T501-03568-0102\500302010103.S3S.mockup
Re: how to pick up the duplicated files only from the greatest versions
My bad! I accidentally added the /R option to the wrong sort (my original version worked fine).
Code and output above are updated.
Code and output above are updated.
Re: how to pick up the duplicated files only from the greatest versions
Thanks again Eureka! Yes worked as expected! Appreciated!
Just a quick question to you.
tasklist | sort (This will sort the list items in ascending order) This will give me the least version.
tasklist | sort /R (This will sort the list items in descending order) This will give me the greatest version.
/+n
Specifies the character number, n, to
begin each comparison. /+3 indicates that
each comparison should begin at the 3rd
character in each line. Lines with fewer
than n characters collate before other lines.
By default comparisons start at the first
character in each line.
So this /+17
\T501-03568-0100\, so this is the part of string to be sorted it out.
Just a quick question to you.
tasklist | sort (This will sort the list items in ascending order) This will give me the least version.
tasklist | sort /R (This will sort the list items in descending order) This will give me the greatest version.
/+n
Specifies the character number, n, to
begin each comparison. /+3 indicates that
each comparison should begin at the 3rd
character in each line. Lines with fewer
than n characters collate before other lines.
By default comparisons start at the first
character in each line.
So this /+17
\T501-03568-0100\, so this is the part of string to be sorted it out.