【问题标题】:How to append to txt file into the last line created previously如何将txt文件附加到先前创建的最后一行
【发布时间】:2019-10-16 11:52:00
【问题描述】:
if 
python python_rule1 >> raw-data.txt

python python_rule2 >> raw-data.txt

if the output from rule1 is A

if the output from rule2 is B

then the raw-data.txt

A

B

我如何获得:

A, B

【问题讨论】:

  • 请将您的示例包装在代码标签中,并在您的帖子中添加您为解决此问题所做的努力。
  • 没问题,但我不太清楚你的意思可以给我一个例子,所以我知道下次该怎么做谢谢
  • 抱歉,这不是 StackOverflow 的工作方式。 “我想做 X,请给我提示和/或示例代码”形式的问题被认为是题外话。请访问help center并阅读How to Ask,尤其是阅读Why is “Can someone help me?” not an actual question?
  • 回声 $((cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2)).$((cat /sys/class/thermal/thermal_zone0/temp|cut -c3-5)) >> /home/pi/Myideas/energy/raw-templog2.txt

标签: linux awk sed


【解决方案1】:

从问题来看,好像有两个程序“python_rule1”和“python_rule2”,产生单字符输出(A或B)。

所需的输出是将两个响应放在标准输出的同一行中,用逗号分隔,而不是发送两行到标准输出。这可以通过将每个步骤的结果存储到 shell 变量(示例中为 R1、R2)中,然后将输出格式化到 stdout 来实现

R1=$(python python_rule1)
R2=$(python python_rule2)
echo "$R1, R2" >> raw-data.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    相关资源
    最近更新 更多