Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3672930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:40:11+00:00 2026-05-19T02:40:11+00:00

why while loop is running only once in this following script? #!/bin/ksh awk ‘

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:40:11+00:00Added an answer on May 19, 2026 at 2:40 am

    Your while line should be

    while ((getline < “portison.result”) > 0)

    otherwise the while comparison is ambiguous and will not be using the result of the getline

    Also as @marco notes you need to close the file with close("portison.result") after the while loop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If, like me, you shiver at the site of a While (True) loop, then
When reviewing, I sometimes encounter this kind of loop: i = begin while (
I wrote a while loop in a function, but don't know how to stop
Is it a good idea to use while loop instead of a cursor? What
How do you write the syntax for a While loop? C # int i
I just want a quick way (and preferably not using a while loop)of createing
When I use an Iterator of Object I use a while loop (as written
While going through university and from following the development of SO, I've heard a
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
While I've seen rare cases where private inheritance was needed, I've never encountered a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.