Created
March 8, 2020 20:29
-
-
Save eschen42/ca2dc46e73b2bb36d5ebc655f47f9797 to your computer and use it in GitHub Desktop.
Windows "here document" as a FileCopy stats extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @set ERRORLEVEL=&setlocal&echo off | |
| if not defined SED_EXE set SED_EXE=sed.exe | |
| set ARG1=%~dpnx1 | |
| if defined ARG1 ( | |
| if exist "%ARG1%" ( | |
| call :sed_here "%~dpnx1" | |
| exit /b %ERRORLEVEL% | |
| ) | |
| ) | |
| echo . | |
| echo usage: "%~nx0" FileCopy_log_to_parse | |
| echo . | |
| echo Here is a trivial example that is possible because "%~nx0" includes an example log | |
| echo "%0" "%0" | |
| echo . & cmd /c ^""%~dpnx0" "%~dpnx0"^" | |
| exit /b -1 | |
| :sed_here | |
| :: Run the sed script in the here document against this file | |
| :: Note that it's necessary to escape selected double quotes, | |
| :: semicolons, and commas; for clarity, I also escaped the | |
| :: hat in the regular expressions for clarity | |
| ( for /f "delims=" %%C in ('^""%SED_EXE%" -n -e "1^,/^^SED_SCRIPT start$/d^; /^^SED_SCRIPT stop$/^,$ d^; p" "%~dpnx0"^"') do @echo %%C ) | "%SED_EXE%" -f - %1 | |
| REM echo exit code %ERRORLEVEL% 1>&2 | |
| exit /b %ERRORLEVEL% | |
| Below is the sed script that will be applied to %~dpnx1, i.e., argument one of this script (%0) | |
| SED_SCRIPT start | |
| # *replace* the hold space with two lines extracted from the pattern space | |
| /^FastCopy/ {s/FastCopy(ver\(.*\)) start at \(.*\)/FastCopyVersion = \1\nStartTime = \2/; h} | |
| # *append* lines matching these patterns to the hold space | |
| /^TotalRead/H | |
| /^TotalWrite/H | |
| /^TotalFiles/H | |
| /^TotalTime/H | |
| /^TransRate/H | |
| /^FileRate/H | |
| /^VerifyRead/H | |
| /^VerifyFiles/H | |
| /^TotalSkip/H | |
| /^SkipFiles/H | |
| # clean up lines matching these patterns and *append* to the hold space | |
| /^<Source> /{s/^.\(Source\). /Origin = /; y/"/'/; H} | |
| /^<DestDir> /{s/^.\(DestDir\). /Target = /; y/"/'/; H} | |
| /^<Exclude> /{s/^.\(Exclude\). /\1 = /; y/"/'/; H} | |
| /^<Command> /{s/^.\(Command\). /\1 = /; y/"/'/; H} | |
| /^<FileLog> /{s/^.\(FileLog\). /\1 = /; y/"/'/; H} | |
| # *append* two lines extracted from the pattern space to the hold space, | |
| # then exchange with the pattern space and print | |
| /^Result/ {s/Result : (ErrFiles : \(.*\) [/] ErrDirs : \(.*\))/ErrFiles = \1\nErrDirs = \2/; H; x; p} | |
| d | |
| SED_SCRIPT stop | |
| Lines below (and including) this line are not processed by this script. | |
| sed commands used in this sed script: | |
| s - substitute https://tinyurl.com/rljdcx2#uh-1 | |
| h - copy pattern space to hold buffer https://tinyurl.com/rljdcx2#uh-55 | |
| H - append pattern space to hold buffer https://tinyurl.com/rljdcx2#uh-55 | |
| x - exchange pattern space with hold buffer https://tinyurl.com/rljdcx2#uh-53 | |
| p - print the pattern space https://tinyurl.com/rljdcx2#uh-31 | |
| d - delete pattern space and read next line https://tinyurl.com/rljdcx2#uh-30 | |
| /.../ - address pattern, not a true command https://tinyurl.com/rljdcx2#uh-27 | |
| Below is an example of a log to parse: | |
| ================================================= | |
| FastCopy(ver3.32) start at 2020/03/07 23:32:53 | |
| <Source> C:\Users\art\src\copyDirToZip\test\small | |
| <DestDir> C:\Users\art\src\copyDirToZip\test\stg\g_demo\PI-small-2020 | |
| <Exclude> .ds_store;desktop.ini;thumbs.db;ehthumbs.db;.spotlight-v100;.documentrevisions-v100;.fseventsd;.mobilebackups;icon;__macosx | |
| <Command> Diff (Size/Date) (with Verify) | |
| <FileLog> C:\Users\art\AppData\Local\log4cmd\PI-small-2020_step\fastcopyDetails_2020-03-08T05-32-50Z_9AB55498.log | |
| ------------------------------------------------- | |
| No Errors | |
| TotalRead = 0.1 MB | |
| TotalWrite = 0.1 MB | |
| TotalFiles = 76 (0) | |
| TotalTime = 0.3 sec | |
| TransRate = 0.44 MB/s | |
| FileRate = 286.8 files/s | |
| VerifyRead = 0.1 MB | |
| VerifyFiles= 76 | |
| Result : (ErrFiles : 0 / ErrDirs : 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment