首先,请原谅我对Windows批处理脚本(甚至是基本脚本)缺乏了解。
我想请求一个有效的Unix脚本的帮助。这是我的工作脚本。
#!/bin/bash
list=`cat view_tags`
for i in $list; do
cleartool lsview -l -prop -full $i | grep "Last accessed" >& /dev/null
if [ $? -eq 0 ]; then
echo -n $i
echo " " `cleartool lsview -reg ccase_win -l -prop -full $i | grep "Last accessed" | awk '{print $3}'`
else
echo $i cannot be found
fi
done
"视图标签"文件包含:
pompei.s1272.hwdig_b12.default
dincsori.arisumf.s2637b_dig.default
tags2
" cleartool的输出lsview -l -prop -full $ i | grep"上次访问":
Last accessed 2017-11-05T11:32:13+01:00 by UNIX:UID-111234.s1272@server1
Last accessed 2013-11-20T16:16:50+01:00 by UNIX:UID-124312.exrt@177.32.5.1
cleartool: Error: No matching entries found for view tag "tags2".
" cleartool的输出lsview -l -prop -full $ i | grep"上次访问":| awk' {print $ 3}'
2017-11-05T11:32:13+01:00
2013-11-20T16:16:50+01:00
cleartool: Error: No matching entries found for view tag "tags2".
tags2 cannot be found
基本上,它将执行命令,cleartool lsview -l -prop -full $ i | grep"上次访问"在文件的每一行" view_tags"。
如果找到字符串"上次访问"在输出上,它将继续打印输出,但如果没有,它会说,"未找到"。
我真的希望有人可以帮助我。非常感谢你提前。
答案 0 :(得分:0)
@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!
)
For /f
将迭代输入文件答案 1 :(得分:0)
以下批处理脚本处理您发布的" view_tags"输入:
@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
应该提供以下输出(虽然我无法测试):
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
如果我使用JREPL.BAT - a regular expression text processing utility written as hybrid batch/JScript:
,我可以消除其中一个FOR / F循环@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