read lines between search pattern

I have a file split something like

01/11/2010:
No of users 100

02/11/2010:
No of users 102

03/11/2010:
No of users 99

...

I want to search the file for a particular date and then extract the following line with the date, something like

02/11/2010 No of users 102

I can grep the date or read the file but now sure how to read the line(s) before the next date?

grep -A1 "02/11/2010" file
grep -A 1 "02/11/2010" your_file | tr -s ":\n" " "

tyler_durden

thanks for the reply, unfortunately grep -A is recognised, I'm using AIX

I guess you mean it is not recognized.

If that's the case then you could use awk to join the pair of lines and then grep just the date of interest.

$
$ cat f45
01/11/2010:
No of users 100
 
02/11/2010:
No of users 102
 
03/11/2010:
No of users 99
 
$
$ awk '/:$/{printf $0 " "} !/:$/{print}' f45 | grep "02/11/2010"
02/11/2010: No of users 102
$
$

Or you could use Perl -

$
$ perl -lne 'BEGIN {$d="02/11/2010"} if (/$d/){printf("%s ",$_); $x=1} elsif ($x){print; $x=0}' f45
02/11/2010: No of users 102
$
$

tyler_durden

Yes both solutions work, many thanks for your help and speedy resonse.:b:

nawk '$1 ~ str {printf $0 OFS;n=1;next} n--==1 {print}' str='02/11/2010' myFile