【发布时间】:2021-07-19 13:42:08
【问题描述】:
我的文件 test.txt 包含一些分配给某个值的变量,我需要读取所有已定义的变量,例如 color = 0;。基本上我想在这里阅读的是参数()->getParm(“”)的前一行的值;
你能帮我弄清楚如何读取这些值吗?还提到了我的预期结果。
cat test.txt
color = 0;
parameters()->getParm(&color, "-color");
width = 16;
parameters()->getParm(&width, "-width");
size = 0;
parameters()->getParm(&size, "-size");
species = "Taxon";
parameters()->getParm(&species, "-species");
fly = 100;
parameters()->getParm(&fly, "-fly");
swim = 25;
parameters()->getParm(&swim, "-swim");
expected result:
color = 0;
width = 16;
size = 0;
species = "Taxon";
fly = 100;
swim = 25;
【问题讨论】:
-
-
can you please help me使用awk,它看起来像一个简短的脚本。 here is sed introduction,但 here is for awk 和 awk 也有 a tutorial on tutorialspoint。grep用于过滤 lines - 在这种情况下,行对您没有帮助,您想从行中提取数据。 -
你的例子可能太琐碎了;
grep -vF 'parameters()->getParm'已经大致按照你的要求做。
标签: linux awk sed command-line grep