我正在尝试根据出现的特定模式从文本文件中提取不同的部分(有时会重复出现)。到目前为止,我已经通过逐行读取文件然后在该行上使用grep命令来完成这个任务,但是我觉得这不是最有效的方法。请看下面的示例模式:
policy-map type stackoverflow
random lines of indented text
non-indented text (signifying the beginning of the next "section" in the file)
还有没有其他的方法可以完成这个任务?我想到了类似awk或sed这样的程序可能会起作用,但是我不熟练使用这些程序,不知道应该如何去做。