简体   繁体   English

使用基于行分隔符的 grep 内容提取文件内容

[英]Extract file content using grep content based on a line delimiter

I'm trying to extract just the file information using either grep, awk or any linux command我正在尝试使用 grep、awk 或任何 linux 命令仅提取文件信息

Have: File有:文件

Getting Table 'TABLEA'
GET TABLE TABLEA
(value(1)
)
/

Getting Table 'TABLEB'
GET TABLE TABLEB
(value(1) 
,other value(2)
)
/

WANT

An output to contain the following包含以下内容的输出

Getting Table 'TABLEA'
GET TABLE TABLEA
(value(1)
)
/

That would work:那会起作用:

grep -A 4 "^Getting Table 'TABLEA'"

It will get the pattern at the start of the line, print it, and continue printing 4 lines afterwards( -A 4 option)它将获取行首的模式,打印它,然后继续打印 4 行( -A 4选项)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM