我试着用NASHORN执行下面的命令,取出一段日志-
$EXEC("sed '1,/Token to find:/d;/Another token to find:/,$d' /path/to/log/file.log")
但结局是-
退出代码:1,错误Msg::sed:-e表达式#1,char 1:未知命令:`‘
在Linux命令提示符下尝试使用相同的命令提示符,下面(用单引号)可以提取日志部分-
sed '1,/Token to find:/d;/Another token to find:/,$d' /path/to/log/fil
我在Linux命令行上,我有具有以下内容的日志文件
Subscription Service Shutdown at 9:59PM UTC
Subscription Service Restarted at 11:57PM UTC
我想为每一行在时间戳之前加上日期
Subscription Service Shutdown at 01 Oct 2016 9:59PM UTC
Subscription Service Restarted at 01 Oct 2016 11:57PM UTC
我试图删除日志文件中的一些特殊行,所以我在嵌入式linux系统上使用sed of busybox。
# sed
BusyBox v1.18.4 (2013-01-16 16:00:18 CST) multi-call binary.
Usage: sed [-efinr] SED_CMD [FILE]...
Options:
-e CMD Add CMD to sed commands to be executed
-f FILE Add FILE contents to sed commands to be executed
-i
Aug 12 01:30:26 server.example.com sshd[19486]: Failed password for root from X.X.X.X port 50528 ssh2
Aug 12 01:30:26 server.example.com sshd[19486]: Received disconnect from X.X.X.X port 50528:11: Bye Bye [preauth]
Aug 12 01:30:26 server.example.com sshd[19486]: Disconnected from X.X.X.X port
给定一个大的日志文件,什么是实现grep的最佳方法?
text to be ignored
more text to be ignored
--- <---- start capture here
lots of
text with separators like "---"
---
spanning
multiple lines
--- <---- end capture here
text to be ignored
more te
我最近将运行ECS EC2实例的AMI从Amazon Linux更改为Amazon Linux2(在这两种情况下,我都使用ECS优化的映像)。我正在使用cloudformation部署我的实例,我真的很头疼,因为这些新实例有时运行成功,有时运行不成功(相同的堆栈,没有更新,相同的代码)。在失败的实例上,我在ECS文件日志"warning: the Amazon ecs Container Agent is not running“中看到ECS服务本身在执行ECS-logs-Colltor.sh时出现了问题。另外,目录"/var/log/ecs“甚至不存在!
我已将正确的IAM角
一种新的linux学习者,这里需要你的帮助。这段代码
sed 's/regexp/&\n/g' file.txt
只在第一次匹配上工作,只在第一次匹配时输出,然后停止读取行的其余部分。
如果我想一直读到最后,然后在每一场比赛中把线移到新的线上,那该怎么办?
例如,我有一个日志文件,如下所示
some text here Critical and some text here Critical and again some text here Critical.
我想像下面这样打破它
some text here
Critical and some text here
C
这是我的样本文件
user@linux:~$ cat file.txt
Line 1
Line 2
Line 3
Line 4
Line 5
user@linux:~$
我可以用grep -A2 'e 2' file.txt打印第2-4行。
user@linux:~$ grep -A2 'e 2' file.txt
Line 2
Line 3
Line 4
user@linux:~$
我也可以用grep -n打印出行号。
user@linux:~$ grep -nA2 'e 2' file.txt
2:Line 2
3-Line 3
4