Derive date and its Volume number

Hi All,
I have a list of date number (YYYYMMDD) and its own number in a file.
Here is the example


20170320
D100001
D100002
D100003
20170321
D200001
D200002
D200004
D200005
20170322
D200005
D200006
D200007

If I grep a date ie. 20170321, I expecting to get the following list
D200001
D200002
D200004
D200005

Once it found next first integer, it will need to stop from proceeding.

Thank You everyone.

Hello ckwan123, Could you please try following and let me know if this helps you.

 awk '/^[0-9]/{val=""} /20170321/{val=1;next} val' Input_file 

Thanks, R. Singh

Not as elegant as intended, but try

awk '$0+0 == $0 {P = 0} $0 == SRCH {P = 1; next} P' SRCH=20170321 file
D200001
D200002
D200004
D200005

Thanks Ravin and RudiC. However, I feel RudiC provided solution is easier to apply into my requirement as it is more flexible by replace the date with a variable. Ravin, yours is able to run with constant value, do you think it can change it to variable ?
RudiC, could you briefly your command ? Thanks so much for your given valuable solution.

Well, if it finds the search phrase, it set the boolean variable P to 1. P is evaluated, and if TRUE (or 1), the line is printed ( awk default behaviour). Later, if an integer is found ($0+0 casts the line to a number or (roughly speaking) to something different if a non-number ist encountered), P is reset to 0 and printing stops.

1 Like