how to extract info from a file using awk

Dear all

I have a file call interfaces.txt

Filename: interfaces.txt

How can I extract the information at below?
ABC_DB_001 hostname1 20901
ABC_DB_002 hostname2 20903
ABC_DB_003 hostname3 20905

Currently I am using a very stupid method

grep ^ABC interfaces.txt > name.txt
grep "master tcp" interfaces.txt > host.txt

total_line=`wc -l name.txt`
i=1
while i < $total_line
do
   name=`head -$i name.txt | tail -1`
   host=`head -#i host.txt | tail -1 | awk '{print $4}`
   port =`head -#i host.txt | tail -1 | awk '{print $5}` 
   echo "$name $host $port"
done

How can I do this using awk? Please give me some idea. Thank you.

Valentino

awk '{print$1,$(NF-1),$NF}' RS= interfaces.txt

Thank you for your help

I google to study what the RS= is. It is to breaks up the line into fields.

However, if my interfaces.txt like this (do not have blank line seperated). How to do then?

Many thanks
Valentino

Use nawk or /usr/xpg4/bin/awk on Solaris.

awk '{printf"%s",(NF==1?$1FS:$(NF-1)FS$NF RS)}' interfaces.txt