bash中,文件的部分解析 [英] bash, parsing part of a file

查看:109
本文介绍了bash中,文件的部分解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,一个文本文件类似如下:

Imagine a text file something like the following:

Case 4
case 4.1
a 3
a 5
a 7
a 1
a 9
a 4
endcase 4.1
//
.
.
. Do things that dont get parsed
.
.
//
case 4.2
a 1
b 3
a 6
b7 
endcase 4.2
endcase 4
//
.
.
.
. More things
.
.
//
case 5
.
.
.
.
endcase 5

,其中包含在不同时间点的多个变量的值。例如,壳体4的关注变量a和b。我如何提取只能说案件4.1之间的界限和ENDCASE 4.1?

which contains the values of multiple variables at different points in time. Eg, case 4 concerns variable a and b. How do I extract only the lines between say case 4.1 and endcase 4.1?

推荐答案

您可以用awk,例如:

You can use awk, for example:

awk '/^case 4.1/,/^endcase 4.1/' ./your_file

这篇关于bash中,文件的部分解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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