bash - 在 shell 脚本中打印数据时格式失败
问题描述
你能帮我看看我用来建立日志的这段代码吗?
##Log construction
printf $timestamp >> $temp"logs.txt"
printf " " >> $temp"logs.txt"
printf $filekey >> $temp"logs.txt"
cat $temp$filekey"_content.txt" >> $temp"logs.txt"
这段代码进入了一个 bash 脚本,其中包含一个循环,该循环运行 N 次,具体取决于某个文本文件的行数(在此示例中,文本文件只有 2 行),问题是打印结果的顺序logs.txt 仅在此脚本第一次运行时就可以了,如下所示:
2020_09_04--10:09:41 myhost1.ec2.local records_found 62
2020_09_04--10:09:41 myhost2.ec2.local records_found 62
下次脚本运行时,它会修改 logs.txt 文件,但会在发现破坏日志格式的最后一个文本之后粘贴结果,如下所示:
2020_09_04--10:09:41 myhost1.ec2.local records_found 62
2020_09_04--10:09:41 myhost2.ec2.local records_found 622020_09_04--10:10:21 myhost1.ec2.local records_found 64
2020_09_04--10:10:21 myhost2.ec2.local records_found 64
预期结果是:
2020_09_04--10:09:41 myhost1.ec2.local records_found 62
2020_09_04--10:09:41 myhost2.ec2.local records_found 62
2020_09_04--10:10:21 myhost1.ec2.local records_found 64
2020_09_04--10:10:21 myhost2.ec2.local records_found 64
非常感谢任何帮助。谢谢。-亚历克斯。
解决方案
推荐阅读
- github - 如何将 GitHub 帐户绑定到法人实体?
- python - 熊猫。基于缺失值和列名的新列
- jquery - 如何正确构建我的代码并且仍然能够使用我的 $(this) var?
- amazon-web-services - 如何从 GitHub Actions 部署 AWS Amplify 应用程序?
- javascript - 如何在 ColorPicker 中设置颜色
- camunda - 卡蒙达。重试服务任务。许多不同的时间间隔
- java - Checkstyles + Gradle throwing 引起:java.lang.IllegalArgumentException:给定名称 COMPACT_CTOR_DEF
- ldap - 使用 ldapsearch gssapi ldap_sasl_interactive_bind_s 错误
- android - Flutter HTTP post请求发送对象列表
- html - 有条件地在 R-markdown 中嵌入视频(bookdown)