Problem extracting data from FILTER list with NO duplicates.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Problem extracting data from FILTER list with NO duplicates.

#1 Post by PAB » 05 Feb 2021 03:48

Good morning,

I hope you are all keeping well and SAFE.

I have been working on something for days and days, and I am so very close to it working but I can't seem to get the last bit to work. I really have tried very hard. He is what I am attempting to do . . .

[1] If the file does NOT exist, show a message - Done and works.
[2] If the file is empty, show a message - Done and works.
[3] If the file does NOT contain TODAYS date, show a message - Does NOT work.
[4] If the file does contain TODAYS date, use a FILTER list to extract the data in the FILTER, delete DUPLICATES, show a message and output the results - Does NOT work.

I have used the TEMP folder for calculations.
It picks up TODAYS date correctly.

The CBS file is correct and shows the correct number of lines.
The FILTER file shows the correct data from the FILTER list for what is in the CBS file.
The TODAY file shows the correct extracted data if there is any from the FILTER list, but has DUPLICATES.
The DUPLICATES file shows the correct data but for ALL days, which is correct, but then I need to extract the data which is TODAYS date ONLY, and also NO DUPLICATES.

On number [3] above, the message shows when there is NO data for TODAY.
On number [4] above, if there is data for TODAY, it outputs the correct data it is asked to via the FILTER list, but includes DUPLICATES [ I just want the last entries for each if there is any ], and gives a message saying "The system cannot find the file specified." I have narrowed it down to this line . . .

Code: Select all

  for /f "tokens=* delims= " %%a in (%Today%) do (
    find "%%a" < %OFN% >nul || >> %OFN% echo.%%a
  )
Here is the code . . .

Code: Select all

@echo off
title Summary [ TODAY ] & mode con: cols=80 lines=9 & color 17
setlocal EnableDelayedExpansion

set "LOG=Corruption_Sum.log"
set "OFN=%Temp%\%LOG%"
set "CBS=%Temp%\CBS_log.txt"
set "Filter=%Temp%\Filter_File.txt"
set "Duplicates=%Temp%\Duplicates.txt"
set "Today=%Temp%\Today.txt"

for /f %%i in ('WMIC OS Get LocalDateTime /Value') do for /f %%j in ("%%i") do set "%%j"
set "Y=%LocalDateTime:~0,4%"
set "M=%LocalDateTime:~4,2%"
set "D=%LocalDateTime:~6,2%"

if exist %OFN% (del /f /q %OFN% >nul 2>&1)

if not exist "%windir%\Logs\CBS\CBS.log" (
  mode con: lines=9 & color C
  echo. & echo THERE IS NO FILE.
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)
for %%a in ("%windir%\Logs\CBS\CBS.log") do ^
if %%~za LEQ 3 (
  mode con: lines=9 & color C
  echo. & echo THE FILE IS EMPTY.
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)
copy "%windir%\Logs\CBS\CBS.log" "%CBS%" >nul
>"%Filter%" (
  echo Summary:
  echo Operation:
  echo Operation result:
  echo Last Successful Step:
  echo Total Detected Corruption:
  echo CBS Manifest Corruption:
  echo CBS Metadata Corruption:
  echo CSI Manifest Corruption:
  echo CSI Metadata Corruption:
  echo CSI Payload Corruption:
  echo Total Repaired Corruption:
  echo CBS Manifest Repaired:
  echo CSI Manifest Repaired:
  echo CSI Payload Repaired:
  echo CSI Store Metadata refreshed:
  echo Total Operation Time:
::echo Not all CSI corruption was fixed
  echo CSI corruption was fixed
  echo Count of times corruption detected:
  echo Failed to run Detect and repair
::echo Reboot mark cleared
  echo Reboot mark
)
type "%CBS%" | findstr /I /G:"%Filter%" >> "%Duplicates%"
for %%R in ("%Duplicates%") do ^
if %%~zR==0 (
  echo. & echo NO SUMMARY [ TODAY ONLY ] WAS FOUND.
  del "%Duplicates%" "%CBS%" "%Filter%"
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
) else (
  del "%Duplicates%"
  cls & mode con: lines=11 & color C
  echo. & echo  SUMMARY [ TODAY ONLY ] WAS FOUND.
  type "%CBS%" | findstr /I /G:"%Filter%" >> "%Duplicates%"
  type "%Duplicates%" | findstr "%Y%-%M%-%D%" >> "%Today%"
  del "%CBS%" "%Filter%"
  for /f "tokens=* delims= " %%a in (%Today%) do (
    find "%%a" < %OFN% >nul || >> %OFN% echo.%%a
  )
  del "%Duplicates%" "%Today%"
  echo. & echo  A LOG has been created.
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)
Am I over complicating this, probably.
I basically want to get the TODAYS entries ONLY, that are contained in the FILTER list, with NO DUPLICATES.

I have several that I want to do like this, so once I can get this sorted out, I will be able to apply this to the others.

Thank you in advance.

EDIT:

I have got a little bit further.
If I change the line above to . . .

Code: Select all

if %%~zR==0 (
. . . I get the data for TODAY with no DUPLICATES, but I get a message "The system cannot find the file specified.".
If I remove that entry from the CBS file so there are NO DATES for TODAY, I get the message "SUMMARY [ TODAY ONLY ] WAS FOUND. A LOG has been created.", although NO log is created which is right. It should actually say "NO SUMMARY [ TODAY ONLY ] WAS FOUND." as per the code.

I think it has got something to do with the ELSE and the BRACKETS.

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Problem extracting data from FILTER list with NO duplicates.

#2 Post by PAB » 07 Feb 2021 10:03

Good afternoon,

Well, I have changed the code and managed to get it to work.
There is however, ONE Error that I can't seem to track down.
When there is data available, I get the message [ I have marked it ]. . .
SUMMARY [ TODAY ONLY ] WAS FOUND.
The system cannot find the file specified. <<<<<<<<<

>Press ANY key to EXIT . . .
Here is the code . . .

Code: Select all

@echo off
title Summary [ TODAY ] & mode con: cols=80 lines=9 & color 17
setlocal EnableDelayedExpansion

set "LOG=Corruption_Sum.log"
set "TFN=%Temp%\%LOG%"
set "OFN=%Desktop%\%LOG%"
set "CBS=%Temp%\CBS_log.log"
set "Filter=%Temp%\Filter_File.log"
set "Duplicates=%Temp%\Duplicates.log"
set "Today=%Temp%\Today.log"

for /f %%i in ('WMIC OS Get LocalDateTime /Value') do for /f %%j in ("%%i") do set "%%j"
set "Y=%LocalDateTime:~0,4%"
set "M=%LocalDateTime:~4,2%"
set "D=%LocalDateTime:~6,2%"

if exist %OFN% (del /f /q %OFN% >nul 2>&1)

if not exist "%windir%\Logs\CBS\CBS.log" (
  mode con: lines=9 & color C
  echo. & echo  THERE IS NO FILE.
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)

for %%a in ("%windir%\Logs\CBS\CBS.log") do ^
if %%~za lss 5 (
  mode con: lines=9 & color C
  echo. & echo  THE FILE IS EMPTY.
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
)

copy "%windir%\Logs\CBS\CBS.log" %CBS% >nul
>"%Filter%" (
  echo Summary:
  echo Operation:
  echo Operation result:
  echo Last Successful Step:
  echo Total Detected Corruption:
  echo CBS Manifest Corruption:
  echo CBS Metadata Corruption:
  echo CSI Manifest Corruption:
  echo CSI Metadata Corruption:
  echo CSI Payload Corruption:
  echo Total Repaired Corruption:
  echo CBS Manifest Repaired:
  echo CSI Manifest Repaired:
  echo CSI Payload Repaired:
  echo CSI Store Metadata refreshed:
  echo Total Operation Time:
::echo Not all CSI corruption was fixed
  echo CSI corruption was fixed
  echo Count of times corruption detected:
  echo Failed to run Detect and repair
::echo Reboot mark cleared
  echo Reboot mark
)
type %CBS% | findstr /I /G:"%Filter%" >> %Duplicates%
type %Duplicates% | findstr %Y%-%M%-%D% >> %Today%
for %%R in (%Today%) do if %%~zR GTR 0 (
  echo. & echo  SUMMARY [ TODAY ONLY ] WAS FOUND.
  for /f "tokens=* delims= " %%a in (%Today%) do (
    find "%%a" < %TFN% >nul || >> %TFN% echo.%%a
  )
  move %TFN% %OFN% >nul 2>&1
  del %CBS% %Filter% %Duplicates% %Today%
) else (
  echo. & echo  NO Summary
  del %CBS% %Filter% %Duplicates% %Today%
  echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit 
)
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit
Thanks in advance.
Last edited by PAB on 07 Feb 2021 15:35, edited 2 times in total.

T3RRY
Posts: 243
Joined: 06 May 2020 10:14

Re: Problem extracting data from FILTER list with NO duplicates.

#3 Post by T3RRY » 07 Feb 2021 10:24

At a quick glance, you are trying to delete the today file while in a loop that has it open for reading.

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Problem extracting data from FILTER list with NO duplicates.

#4 Post by PAB » 07 Feb 2021 10:31

Thank you for the reply, it is appreciated.

I took out ALL the deletes and I still get the same message!

I think it has something to do with this because it appears AFTER the line . . .
echo. & echo SUMMARY [ TODAY ONLY ] WAS FOUND.

Code: Select all

  for /f "tokens=* delims= " %%a in (%Today%) do (
    find "%%a" < %TFN% >nul || >> %TFN% echo. %%a
  )
Thanks in advance.

EDIT:

This is strange. If I add . . .
>>%TFN% echo %~nx0 & >> %TFN% echo.
. . . here . . .

Code: Select all

for %%R in (%Today%) do if %%~zR GTR 0 (
  echo. & echo  SUMMARY [ TODAY ONLY ] WAS FOUND.
>>%TFN% echo Filename: %~nx0 & >> %TFN% echo.
  for /f "tokens=* delims= " %%a in (%Today%) do (
    find "%%a" < %TFN% >nul || >> %TFN% echo.%%a
  )
I DON'T get the Error message!

Post Reply