Range patterns are useful but not flexible. Instead of using them, maintain the between-or-not state in a variable. The awk script /select/,/from/ is equivalent to

/select/ {printing = 1}
printing {print}
/from/ {printing = 0}


If you want to limit the range to a number of lines, maintain a counter of lines seen and accumulate the output until you've decided whether to display it.

/select/ {select_text = $0; select_line_count = 1;}
select_line_count {select_text = select_text "\n" $0}
/from/ {if (select_line_count &lt;= 10) {print select_text; print}
        select_line_count = 0}


You'll probably want to refine the pattern, for example to require that select is at the beginning of the line except for whitespace, and is followed by whitespace: /^[\t ]*select($|[\t ])/

Is there a way to limit the range of the range pattern in awk?
In our Android application we have a list view of items. The items can be members of two different groups, Group 1 and Group 2, but can also be without group. To filter the list to show the items in a specific group we use a segment control, one segment for showing All, one for Group 1 and one for Group 2.







download bmml source &ndash; Wireframes created with Balsamiq Mockups

Now we want to add a third group, Group 3, and the width is becoming a bit stressed. To be honest, the third group will not fit in this structure at all on the smaller screen models.

I am looking for a temporary quick solution for this problem. The idea to include a side bar to specify filtering is already in the pipeline, but it will be some time before we can release a version with this included, and the new group must be visible as soon as possible.

Therefore, I have an idea of adjusting the segment control, enabling a null selection instead of the All filter. That would open up a free space and the new filter group could be included. Problem is though that I'm finding it hard to argument for this solution, mainly because I have not seen it practised elsewhere as I can remember. 
I have thought about having the segment control scrollable, similar to that of the top shortcut bar in the Android notification view, though that sounds like a more expensive solution.

The segment control is in essence an evolved radio button group/tab control, and making it possible to deselect a tab/button is at first thought not a very attractive idea I admit.

I am looking for feedback on this idea, references to similar solutions, or another cheap solution that would fit into this context.
