Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. ...
  2. ... TYPE: alm01, ........
  3. ...
  4. ...
  5. ...
  6. ... TYPE: almBB, ........
  7. ...
  8. ...
  9. ... TYPE: out, ......
  10. ...
  11. ... TYPE: in, ......
  12. ... TYPE: almBB, ........
  13. ... TYPE: out, ......
  14. ... TYPE: out, ......
  15.  
  16. alm01 1
  17. almBB 2
  18. out 3
  19. in 1
  20.  
  21. @echo off
  22. setlocal enableextensions enabledelayedexpansion
  23.  
  24. rem Configuration
  25. set "file=test.log"
  26.  
  27. rem Clean environment
  28. for /f "tokens=1 delims==" %%v in ('set _type_ 2^>nul') do set "%%v="
  29.  
  30. rem Search required lines
  31. for /f "tokens=*" %%l in ('findstr "TYPE:" "%file%"') do (
  32.  
  33. rem Now we have the whole line
  34.  
  35. set "t=%%l"
  36.  
  37. rem Remove the prefix of the line
  38. set "t=%t:*TYPE: =%"
  39. set "t=%t:~1%"
  40.  
  41. rem Remove the suffix of the line (from comma to end) and
  42. rem increment counter of type
  43. for /f "tokens=1 delims=," %%t in ('echo %t%') do set /a "_type_%%t+=1"
  44. )
  45.  
  46. rem Enumerate find types and echo type and number of occurrences
  47. rem The inner loop is to allow underscores inside type
  48. for /f "tokens=1,* delims=_" %%a in ('set _type_ 2^>nul') do (
  49. for /f "tokens=1,2 delims==" %%v in ("%%a") do echo %%v %%w
  50. )
  51.  
  52. rem Clean and exit
  53. endlocal
  54. exit /b
  55.  
  56. @echo off
  57. setlocal enableextensions disabledelayedexpansion
  58.  
  59. rem Configuration
  60. set "file=plaintext.txt"
  61.  
  62. rem Clean environment
  63. for /f "tokens=1 delims==" %%v in ('set _type_ 2^>nul') do set "%%v="
  64.  
  65. rem Search required lines
  66. for /f "tokens=*" %%l in ('findstr "TYPE:" "%file%"') do (
  67.  
  68. rem Now we have the whole line
  69. set "t=%%l"
  70.  
  71. rem Can't handle it inside the for loop. Go out to do it
  72. call :handleType
  73. )
  74.  
  75. rem Enumerate find types and echo type and number of occurrences
  76. rem The inner loop is to allow underscores inside type
  77. for /f "tokens=1,* delims=_" %%a in ('set _type_ 2^>nul') do (
  78. for /f "tokens=1,2 delims==" %%v in ("%%b") do echo %%v %%w
  79. )
  80.  
  81. rem Clean and exit
  82. endlocal
  83. exit /b
  84.  
  85. :handleType
  86. rem Remove the prefix of the line
  87. set "t=%t:*TYPE: =%"
  88. rem Remove spaces (not needed as OP stated and giving problems)
  89. set "t=%t: =%"
  90.  
  91. rem Remove the suffix of the line (from comma to end) and
  92. rem increment counter of type
  93. for /f "tokens=1 delims=," %%t in ("%t:"=%") do set /a "_type_%%~t+=1"
  94.  
  95. goto :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement