使用 bash 打印与模式匹配的同一行的多个部分

Printing multiple parts of the same line matching a pattern using bash

我正在编写一个 unix 命令来获取在位置 87-90 匹配 abcd 的行,对于匹配此条件的行,它应该让我得到位置 10-15、124-128,250-265.I 尝试了这样的事情.

grep -h abcd  sample.txt |cut -c 10-15,cut -c 124-128,cut -c 250-260

尽管这在语法上是错误的,但我希望它传达了我想要表达的意思achieve.Could你能帮我连接多次切割的所有结果吗?

cut -c 接受字符列表。如手册页所述,"each list is made up of one range, or many ranges separated by commas."

grep -h abcd sample.txt | cut -c 10-15,124-128,250-260