Windows Equivalent of Unix Shell Script

寵の児 提交于 2019-12-06 15:38:12
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
For /f "delims=" %%A in ('Type view_tags') do (
  Set "Out=%%A can nnot be found"
  For /f "tokens=3" %%B in (
    'cleartool lsview -reg ccase_win -l -prop -full %%A ^| Find "Last accessed" 2^>Nul '
  ) Do Set "Out=%%B"
  Echo !Out!
)
  • The first For /f will iterate the input file
  • The 2nd one will parse the output of cleartool, getting the 3rd space delimited string of each line.

The following batch script processing your posted "view_tags" input:

@echo off
for /f "delims=" %%A in (view_tags) do (
  for /f "tokens=3" %%B in (
    'cleartool lsview -reg ccase_win -l -prop -full "%%A" 2^>nul ^| find "Last accessed"'
  ) do echo %%A: %%B
) || echo %%A: Not Found

Should give the following output (though I'm not able to test):

pompei.s1272.hwdig_b12.default: 2017-11-05T11:32:13+01:00
dincsori.arisumf.s2637b_dig.default: 2013-11-20T16:16:50+01:00
tags2: Not Found

I can eliminate one of the FOR /F loops if I use JREPL.BAT - a regular expression text processing utility written as hybrid batch/JScript:

@echo off
for /f "usebackq delims=" %%A in ("view_tags") do ^
  cleartool lsview -l -prop -full "%%A" 2>nul | ^
  jrepl "Last accessed (\S+)" "$txt='%%A: '+$1" /jmatchq || echo %%A: Not Found
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!