Windows 等价于 Unix Shell 脚本
Windows Equivalent of Unix Shell Script
首先,请原谅我对 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 }'`
else
echo $i cannot be found
fi
done
"view tags" 文件包含:
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 "Last accessed" 文件的每一行 "view_tags"。
如果在输出中找到字符串 "Last accessed",它将继续打印输出,但如果没有,它会说 "not found".
我真的希望有人能帮助我解决这个问题。非常感谢您。
@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
将迭代输入文件
- 第二个将解析 cleartool 的输出,获取每行的第 3 个 space 分隔字符串。
以下批处理脚本处理您发布的 "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: '+" /jmatchq || echo %%A: Not Found
首先,请原谅我对 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 }'`
else
echo $i cannot be found
fi
done
"view tags" 文件包含:
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 "Last accessed" 文件的每一行 "view_tags"。
如果在输出中找到字符串 "Last accessed",它将继续打印输出,但如果没有,它会说 "not found".
我真的希望有人能帮助我解决这个问题。非常感谢您。
@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
将迭代输入文件 - 第二个将解析 cleartool 的输出,获取每行的第 3 个 space 分隔字符串。
以下批处理脚本处理您发布的 "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: '+" /jmatchq || echo %%A: Not Found