why while loop is running only once in this following script?
#!/bin/ksh
awk '
{site=$1; print $2;
while (getline <"portison.result")
{
var=substr($2, 0, 3)
if (site == var)
print $0
}
}
' sites.cfg
portison.result file contains:
0 AGAMS3 EDGE NTS 2347629,,,RHe
10 AGNSD9 EDGE NTS 2340447,,,TRf
100 AGBSN0 EDGE NTS 2323735,,,BRc
2 AGUMS3 EDGE NTS 2347629,,,RHe
20 AGWSD9 EDGE NTS 2340447,,,TRf
200 AGLSN0 EDGE NTS 2323735,,,BRc
3 AGDMS3 EDGE NTS 2347629,,,RHe
30 AGSSD9 EDGE NTS 2340447,,,TRf
300 AGESN0 EDGE NTS 2323735,,,BRc
4 AGNSD9 EDGE NTS 2340447,,,TRf
40 AGAMS3 EDGE NTS 2347629,,,RHe
400 AGCSN0 EDGE NTS 2323735,,,BRc
5 AGISN0 EDGE NTS 2323735,,,BRc
500 AGISN0 EDGE NTS 2323735,,,BRc
sites.cfg contains:
AGA Glasgow AQ
AGN Newport TR
AGB Bridgend BR
AGU Sunderland RH
AGW Swansea SW
AGL Marine Wharf MW
AGD Dudley DU
AGS Brighton SU
AGE Southend ES
AGC Solent CH
AGI Isle of Man IM and PB
I want output as:
Glasgow
0 AGAMS3 EDGE NTS 2347629,,,RHe
40 AGAMS3 EDGE NTS 2347629,,,RHe
Newport
10 AGNSD9 EDGE NTS 2340447,,,TRf
4 AGNSD9 EDGE NTS 2340447,,,TRf
Bridgend
100 AGBSN0 EDGE NTS 2323735,,,BRc
Sunderland
2 AGUMS3 EDGE NTS 2347629,,,RHe
Swansea
20 AGWSD9 EDGE NTS 2340447,,,TRf
Marine
200 AGLSN0 EDGE NTS 2323735,,,BRc
Dudley
3 AGDMS3 EDGE NTS 2347629,,,RHe
Brighton
30 AGSSD9 EDGE NTS 2340447,,,TRf
Southend
300 AGESN0 EDGE NTS 2323735,,,BRc
Solent
400 AGCSN0 EDGE NTS 2323735,,,BRc
Isle
5 AGISN0 EDGE NTS 2323735,,,BRc
500 AGISN0 EDGE NTS 2323735,,,BRc