I am using the following code
我正在使用下面的代码。
ff=`date +%h" "%Oe`
pd=`date -d'yesterday' +%h" "%Oe`
aa=`date -d'yesterday' +%d\/%m\/%Y`
bb=`date +%d\/%m\/%Y`
for j in `ls -lrt |egrep "$ff|$pd"|awk -F " " '{print $9}'`
do
sed -n "/${aa}/,/${bb}/p" ${j}
done
Logs from where I am fetching the data looks something like this
我从那里获取数据的日志看起来是这样的
[2015-01-07 18:39:18,212] host123 WARN com.host123 .elf.UserQuest -
Quest/option {o.q.more.paper.osc#0} references unknown dependent
{t.what.form.file.more.action} in application {src-code}. Please
revise.
[2015-01-07 18:39:18,212] host123 WARN com.host123 .elf.UserQuest -
Quest/option {o.q.more.paper.osc#1} references unknown dependent
{t.what.form.file.more.action} in application {src-code}. Please
revise.
[2015-01-07 18:40:34,281] cessor32 ERROR com.host123
.email.DirectMailer - Unable to connect to server {1.1.1.1}:
javax.mail.MessagingException: Could not connect to SMTP host:
1.1.1.1, port: 25, response: 451
at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:996)
at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at
com.host123.email.DirectMailer.deliverMessage(DirectMailer.java:191)
I am getting the following error after executing the script
在执行脚本之后,我将得到以下错误
sed: -e expression #1, char 5: unknown command: `0'
Please do suggest something.
请建议什么。
3 个解决方案
#1
2
The issue here is that you're using the /
delimiter in your sed command, while at the same time using patterns that contain the same character. Try changing your sed command to this:
这里的问题是,您在sed命令中使用/分隔符,同时使用包含相同字符的模式。尝试将您的sed命令更改为以下命令:
sed -n "\#${aa}\#,\#${bb}\#p" "$j"
As NeronLeVelu has mentioned in the comments (thanks), it is necessary to escape the character with a backslash.
正如NeronLeVelu在评论中提到的(谢谢),有必要用反斜杠来转义字符。
Alternatively, you could use awk to print your range of lines:
您也可以使用awk打印您的行范围:
awk -v s="$aa" -v e="$bb" '$0 ~ s, $0 ~ e' "$j"
#2
0
Tried making array out of ls -lrt |egrep "$ff|$pd"|awk -F " " '{print $9}'
then loop through array?
尝试用ls -lrt |构建数组,然后循环遍历数组?
#3
0
The problem is that value of bb
contains /
s (Your sed
command also using /
as delimiter) . Try changing the line to:
问题是bb包含/s的值(您的sed命令也使用/作为分隔符)。试着把线改为:
sed -n "#${aa}#,#${bb}#p" ${j}
Another suggestion is to use the newer format of ff=$(date +%h" "%Oe)
另一个建议是使用ff=$(日期+%h”“%Oe)的新格式
#1
2
The issue here is that you're using the /
delimiter in your sed command, while at the same time using patterns that contain the same character. Try changing your sed command to this:
这里的问题是,您在sed命令中使用/分隔符,同时使用包含相同字符的模式。尝试将您的sed命令更改为以下命令:
sed -n "\#${aa}\#,\#${bb}\#p" "$j"
As NeronLeVelu has mentioned in the comments (thanks), it is necessary to escape the character with a backslash.
正如NeronLeVelu在评论中提到的(谢谢),有必要用反斜杠来转义字符。
Alternatively, you could use awk to print your range of lines:
您也可以使用awk打印您的行范围:
awk -v s="$aa" -v e="$bb" '$0 ~ s, $0 ~ e' "$j"
#2
0
Tried making array out of ls -lrt |egrep "$ff|$pd"|awk -F " " '{print $9}'
then loop through array?
尝试用ls -lrt |构建数组,然后循环遍历数组?
#3
0
The problem is that value of bb
contains /
s (Your sed
command also using /
as delimiter) . Try changing the line to:
问题是bb包含/s的值(您的sed命令也使用/作为分隔符)。试着把线改为:
sed -n "#${aa}#,#${bb}#p" ${j}
Another suggestion is to use the newer format of ff=$(date +%h" "%Oe)
另一个建议是使用ff=$(日期+%h”“%Oe)的新格式