@echo off rem -- Split a trace file into separate trace level files. rem rem -- The split is based on the trace option, which is determined rem -- automatically from those present in the file. rem -- rem -- If the optional device name is specified, then output files are produced rem -- only for the options pertaining to that device, and each file contains rem -- only the trace lines for that device. If the device is not specified, rem -- then files are produced for all options, and each contains trace lines rem -- for all devices that match the option. if exist "%1" goto :ok echo. echo Usage: split [filename in the current directory] [[device name]] echo. echo If the device name is not specified, then all device names are split. goto :end :ok rem -- Process: rem -- 1. gsort is used to sort the log file by the device name and trace rem -- option and then output only the first line of each unique key. rem -- rem -- 2. sed is used to reduce each trace line to just the trace option of rem -- the specified device or of all devices if one was not specified. rem -- rem -- 3. gsort is used to sort the trace options and retain only the unique rem -- ones in case a device was not specified. rem -- rem -- 4. for is used to iterate through the set of trace options. rem -- rem -- 5. grep is used to pick out the trace lines that match the current rem -- option and write them to a file whose extension includes that rem -- option. rem -- rem -- Note: Cygwin's sort is used because its version (8.25) is about 6-7 times rem -- faster than GNUWin32's version (5.3.0). If a new mingw version is rem -- compiled, then it can be used intead. for /F %%i in ('E:\Programming\Cygwin\root\bin\sort --key=1^,2 --unique %1 ^| sed -n -r -e "s/>>%2.+ ([a-z]+):.+$/\1/p" ^| gsort --unique') do grep -E -e ">>%2.* %%i:" %1 > %~n1.%%i%~x1 :end