为不同的文件运行命令并存储输出结果

时间:2022-10-18 08:20:24

I have a lot of files in my computer and I need to run a program with some commands in order to evaluate this files and get some results. The commands for evaluating one of the files are something like this:

我的电脑里有很多文件,我需要运行一个包含一些命令的程序来评估这些文件并得到一些结果。评估其中一个文件的命令如下:

./abc
abc 01> read_verilog myfile1.v
abc 02> sat
abc 03> quit

after running the "sat" command, some results will be shown in the terminal and I need to store them in a .txt file. I have written a script to run this commands (below) for 1000 files but my problem is that I cannot store the output of "sat" command for all of these files.

运行了“sat”命令后,终端将显示一些结果,我需要将它们存储在.txt文件中。我已经为1000个文件编写了运行这些命令的脚本(如下),但是我的问题是我不能为所有这些文件存储“sat”命令的输出。

  #!/bin/bash
# since Bash v4
for i in {1..1000..1}
do
    ./abc <<EOF
    read_verilog "myfile$i.v"
    sat
    quit
    EOF
done

1 个解决方案

#1


2  

You can write the output of here-doc to a target output file as below

您可以将here-doc的输出写入目标输出文件,如下所示

./abc <<EOF > /tmp/outputfile"${i}".txt
read_verilog "myfile$i.v"
sat
quit
EOF

The target output path can be anything, not essentially be under /tmp, could just be outputfile"${i}".txt

目标输出路径可以是任何东西,而不是在/tmp下,可以是outputfile“${i}”.txt

#1


2  

You can write the output of here-doc to a target output file as below

您可以将here-doc的输出写入目标输出文件,如下所示

./abc <<EOF > /tmp/outputfile"${i}".txt
read_verilog "myfile$i.v"
sat
quit
EOF

The target output path can be anything, not essentially be under /tmp, could just be outputfile"${i}".txt

目标输出路径可以是任何东西,而不是在/tmp下,可以是outputfile“${i}”.txt