我有一个像这样的地形脚本
pipeline_schedules = [{ <== ( I know this line number through a grep command )
description = "pipeline1"
ref = "5.2.0"
cron = ""
variables = []
}, {
description = "pipeline2"
ref = "5.2.1"
cron = ""
variables = []
}] # <== ( I want to find this line number )
通过bash脚本,我想找到pipeline_schedules
数组末尾的行号,假设我知道数组开始的行号。如果不是因为数组中存在其他数组(variables = []
),它会很简单。
请帮忙好吗?
背景就好了!你到底想用这些行号做什么?
你用grep找到了左括号的行号,你也可以用grep找到右括号:
grep -n '^}]'
-
使用正则表达式,包括n*作为结束行
-
如果您试图提取信息,请使用向前看和捕获组。也可以考虑使用
sed
-
如果你试图修改资源文件,regex,向前看,捕获组和sed是你的答案。