separate a line having particular field

hi
i have a file containes data like,

20081013-030618.675199 [2712] D 17 Change state DATA_RECEIVE->EOD, RC=0
20081013-030618.868358 [2712] D 17 Reading data...
20081013-030618.868498 [2712] D 18 Received 5 bytes
20081013-030618.868537 [2712] U Buffer received:

now i need to cut the 4th field i.e 17 and write that line into a separate file

please help

thanks in advance
Satya

awk '{print $4}' datafile > newfile

Looks like sometimes that field doesn't appear. So you might want to augment it with:

awk '$3 == "D" { print $4 }' datafile >newfile

And just pipe through "sort -u" so that you have only unique id's.