简体   繁体   English

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

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

I am writing a unix command to get lines matching abcd at position 87-90 and for the lines matching this critieria it should get me position 10-15, 124-128,250-265.I tried something like this. 我正在写一个unix命令来获取与abcd相匹配的行在位置87-90,对于与该critieria相匹配的行,它应该使我位于位置10-15,124-128,250-265。

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

Though this is syntactically wrong I hope it conveys what I am trying to achieve.Could you help me concatenate all the results from the multiple cuts? 尽管从语法上讲这是错误的,但我希望它能传达我想要达到的目标。您能帮我将多次切割的所有结果合并起来吗?

cut -c accepts a list of characters. cut -c接受字符列表。 As described in the man page, "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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM