所以我想做一些日志记录,因此,想在 bash 脚本的输出前面放一个日期。问题是它有多行输出。我只能将日期放在整个输出之前。但是后来我在日志中有一行没有日期。当然,我可以假设上一行的日期是相同的,但我希望有一个解决方案。提前致谢!
这是我调用另一个脚本的脚本:
#!/bin/sh
echo $(date "+%F %T") : starting script
echo $(date "+%F %T") : $(./script.sh)
echo $(date "+%F %T") :script ended
Run Code Online (Sandbox Code Playgroud)
这是输出:
2012-07-26 15:34:12 : starting script
2012-07-26 15:35:14 : First line of output
second line of output
2012-07-26 15:35:17 : script ended
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:
2012-07-26 15:34:12 : starting script
2012-07-26 15:35:14 : First line of output
2012-07-26 15:35:15 : second line of output
2012-07-26 15:35:17 : script ended
Run Code Online (Sandbox Code Playgroud) 我希望我的问题表述正确。我有一个大量使用“sed”的脚本。它在我的带有 GNU 'sed' 的 ubuntu 上运行良好。但是当我尝试在 BusyBox 上运行它时,它失败了。有没有办法在busybox上获得GNU sed?我不是 Linux 专家。
我有一个带有文本和几个 URL 的字符串。如何使用 sed 提取一个特定的 URL(特定域的)?例如,我有这个:
Text foo bar Text foo bar <br /><br /> http://www.this.file <br />http://another.file <br />http://mine.com/this.html <br />http://myURL.net/files/IWANTthis <br />http://www.google.com/thisnot
Run Code Online (Sandbox Code Playgroud)
并sed
应返回:
http://myURL.net/files/IWANTthis
所以我有一个curl
通过管道连接到 agrep
和 a 的sed
。我会在哪里申请>/dev/null 2>&1
?
curl www.site.com | grep stuff | sed "other stuff"
Run Code Online (Sandbox Code Playgroud)
在最后还是在卷曲之后?