我必须获取特定版本(例如 v2.0.1 或 v2.0.2 等)的特殊行
例如,对于输入“v2.0.2”,我想要以下输出:
==2012-01-02 v2.0.2
some information about B..
这是我的文本文件 sample.txt:
==2012-01-01 v2.0.1
some information about A..
==2012-01-02 v2.0.2
some information about B..
==2012-01-03 v2.0.4
some information about C..
最佳答案
awk -v s="$ver" 'BEGIN{gsub(/\./,"[.]",s)}$0~s{p=7;print;next}p&&/^==/{p=0}p' file
$ver
是一个 shell 变量,包含搜索字符串。
BEGIN{}
block 用于转义 。 (点)
,因为稍后我们会将其用作动态正则表达式。
关于linux - 在文本中找到特殊 block ,使用 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25263203/