Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    You say "don't have any luck in getting the line from pattern A to B" but you apparently want all the lines from patterm B to pattern A, at least that's whet you show in the desired output. Your first language is probably not English, but please try to edit your question to make it clearer what you want. Commented Feb 8, 2018 at 10:17
  • 1
    there's no Pattern B: B=AK2 in your input content. Update your question Commented Feb 8, 2018 at 10:18
  • @wurtel, There are two Pattern B which is the AK2 in the example_text.file. I don't want to print all the lines from pattern B to A. As you can see I separated them in my desired output. I want a command that finds first pattern A and then move to previous lines until the first match of pattern be is found. In the example_file.txt the first match of pattern A is in line number 12. So from that point it moves up until first occurrence of pattern B is matched which is in line number 7. The same goes to the 2nd pattern A matched where pattern B is in line number 15. Commented Feb 9, 2018 at 0:12
  • @RomanPerekhrest, There is in line number 5: AK2*777*6666666, line number 7: AK2*777*7777777, line number 13: AK2*777*6666666, and line number 15: AK2*777*7777777. Sorry, I think you have literally see B=AK2 as the whole pattern. It's only AK2 is the pattern. I just put it in a variable B for representation of consistent pattern I want to find. Anyways, I'm just gonna correct this section to prevent confusion. Thanks Commented Feb 9, 2018 at 0:20
  • Yes, sed could extract the ranges: tac ../infile | sed -ne '/^AK5\*R/,/AK2\*/p' | tac. What it could not do is redirect each range to a separate file. Commented Feb 9, 2018 at 2:48