Windows等效于Unix Shell脚本 [英] Windows Equivalent of Unix Shell Script

查看:99
本文介绍了Windows等效于Unix Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请原谅我对Windows批处理脚本(甚至是基本语言)缺乏知识.

To begin, please excuse my lack of knowledge on windows batch scripting (even the basic).

我想就等效的Unix脚本寻求帮助.这是我的工作脚本.

I would like to ask for help on the equivalent of a working Unix script. This is the working script that I have.

#!/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

  1. 视图标签"文件包含:

  1. The "view tags" file contain:

pompei.s1272.hwdig_b12.default
dincsori.arisumf.s2637b_dig.default
tags2

  • "cleartool lsview -l -prop -full $ i | grep最近访问"的输出:

  • The output of "cleartool lsview -l -prop -full $i | grep "Last accessed":

    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}'

  • The output of "cleartool lsview -l -prop -full $i | grep "Last accessed": | 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"的每一行上的最近访问".

    Basically, it will execute the command, cleartool lsview -l -prop -full $i | grep "Last accessed" on each line of the file "view_tags".

    如果在输出上找到字符串"Last access",它将继续打印输出,但如果没有,它将显示"not found".

    If it finds a string "Last accessed" on the output, it will proceed to print the output but if not, it will say, "not found".

    我真的希望有人可以对此提供帮助.提前非常感谢您.

    I really hope someone can help me on this. Thank you very much in advance.

    推荐答案

    @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的输出,获取每行的第三个以空格分隔的字符串.
      • 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.
      • 这篇关于Windows等效于Unix Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆