使用awk搜索模式并从日志文件中打印下15行 [英] Searching a pattern using awk and print next 15 lines from a log file

查看:114
本文介绍了使用awk搜索模式并从日志文件中打印下15行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用awk搜索模式并从日志文件中打印下15行

Searching a pattern using awk and print next 15 lines from a log file

awk '/^DERAT1SB[0-9][0-9]# show registration/{nr[NR]; nr[NR+4]}; NR in nr' slb.log

我正在使用上述命令在日志文件中搜索模式DERAT1SB23# show registration,但是它抛出语法错误.

I am using above command to search a pattern DERAT1SB23# show registration inside a log file, but it is throwing a syntax error.

错误:

awk: syntax error near line 1

awk: bailing out near line 1

推荐答案

来自 有效的Awk编程,第4版 :

其他名字的玫瑰 awk语言已经发展了多年.完整的详细信息请参见附录A [ [awk语言],第439页.本书中所描述的语言通常是 称为新awk".以此类推,awk的原始版本是 称为旧awk".

A Rose by Any Other Name The awk language has evolved over the years. Full details are provided in Appendix A [The Evolution of the awk Language], page 439. The language described in this book is often referred to as "new awk." By analogy, the original version of awk is referred to as "old awk."

在大多数当前系统上,当您运行 awk实用程序,您会获得一些新版本的awk. 4 如果您的系统是 标准awk是旧的awk,如果您看到 尝试测试程序:

On most current systems, when you run the awk utility you get some version of new awk.4 If your system’s standard awk is the old one, you will see something like this if you try the test program:

$ awk 1 /dev/null
error awk: syntax error near line 1
error awk: bailing out near line 1

在这种情况下,您 应该找到新awk的版本,或者只是安装gawk!

In this case, you should find a version of new awk, or just install gawk!

穿越 这本书,每当我们提到语言功能时, 在POSIX awk的任何完整实现中都可用,我们只需使用 术语awk.当指代特定于GNU的功能时 实施中,我们使用术语gawk.

Throughout this book, whenever we refer to a language feature that should be available in any complete implementation of POSIX awk, we simply use the term awk. When referring to a feature that is specific to the GNU implementation, we use the term gawk.

4 仅Solaris系统仍将旧的awk用于默认的awk实用程序.在这些系统上的/usr/xpg6/bin中居住着更现代的awk.

4 Only Solaris systems still use an old awk for > the default awk utility. A more modern awk lives in /usr/xpg6/bin on these systems.

这篇关于使用awk搜索模式并从日志文件中打印下15行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆