简体   繁体   中英

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.

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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