Harish
Harish

Reputation: 3483

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?

Upvotes: 0

Views: 252

Answers (1)

John Kugelman
John Kugelman

Reputation: 361575

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

Upvotes: 1

Related Questions