【问题标题】:Shell script to verify data packages用于验证数据包的 Shell 脚本
【发布时间】:2019-02-20 02:56:30
【问题描述】:

我需要制作 shell 脚本来使用大量数据检查我的算法(测试包保存在 .in 文件中,每个包都包含带有 .in 文件的文件夹,另一个带有 .out 文件的文件夹应该是正确的结果) 有时一个包中大约有 1000 个文件,因此手动进行是没有意义的。我需要某种循环来打开这个 .in 文件,然后重定向我的 c++ 程序的输入并重定向这个程序的输出(将结果保存到 .out 文件)但关键是我不能像我需要的那样快速获得这种语言. 我希望这个脚本可以将我的算法结果与包中的 .out 文件进行比较

for f in ExternalIn/*.in; do//part of code which opens process with my algorithm and compare its .out file to .out file from package

【问题讨论】:

    标签: macos function shell unix


    【解决方案1】:

    跳过对丢失文件、空白安全等的检查,您可能需要以下内容:

    for f in ExternalIn/*.in; do
        # diff the result of my_cpp_app eating file.in with file.out
        # and store the comparison result in file.diff
        diff ${f/.in/.out} <(my_cpp_app <$f 2>/dev/null) > ${f/.in/.diff}
    done
    

    虽然我可能会使用 find / xargs 管道来执行此操作,这不仅更安全,而且允许并行执行。

    或者甚至为此写一个Makefile 并使用make,毕竟它是完成此类工作的工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多