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 6029409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:52:54+00:00 2026-05-23T04:52:54+00:00

This is the exact code I am running in my system with sh lookup.sh

  • 0

This is the exact code I am running in my system with sh lookup.sh. I don’t see any details within nawk block printed or written to the file abc.txt. Only I am here 0 and I am here 1 are printed. Even the printf in nawk is not working. Please help.

processbody() {
nawk '
NR == FNR {
split($0, x, "@")
country_code[x[2]] = x[1]
next
system(" echo " I am here ">>/tmp/abc.txt") 
}
{
CITIZEN_COUNTRY_NAME = "INDIA"
system(" echo " I am here 1">>/tmp/abc.txt") 
if (CITIZEN_COUNTRY_NAME in country_code) {
value = country_code[CITIZEN_COUNTRY_NAME]
system(" echo " I am here 2">>/tmp/abc.txt") 
} else {
value = "null"
system(" echo " I am here 3">>/tmp/abc.txt") 
}
system(" echo " I am here 4">>/tmp/abc.txt") 
print "found " value " for country name " CITIZEN_COUNTRY_NAME  >> "/tmp/standalone.txt"
} ' /tmp/country_codes.config
echo "I am here 5" >> /tmp/abc.txt
}

# Main program starts here
echo "I am here 0" >> /tmp/abc.txt
processbody 

And my country_codes.config file:

$ cat country_codes.config
IND@INDIA
IND@INDIB
USA@USA
CAN@CANADA
  • 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-23T04:52:55+00:00Added an answer on May 23, 2026 at 4:52 am

    That’s some pretty interesting awk code. The problem is that your first condition, the NR == FNR one, is active for each record read from the first file – the country_codes.config file, but the processing action contains next so after it reads a record and splits it and saves it, it goes and reads the next record – not executing the second block of the awk script. At the end, it is done – nothing more to do, so it never prints anything.

    This works sanely:

    processbody() 
    {   
        awk '
            {
            split($0, x, "@")
            country_code[x[2]] = x[1]
            #next
            }
        END {
            CITIZEN_COUNTRY_NAME = "INDIA"
            if (CITIZEN_COUNTRY_NAME in country_code) {
                value = country_code[CITIZEN_COUNTRY_NAME]
            } else {
                value = "null"
            }
            print "found " value " for country name " CITIZEN_COUNTRY_NAME
        } ' /tmp/country_codes.config
    }   
    
    # Main program starts here
    processbody
    

    It produces the output:

    found IND for country name INDIA
    

    As Hai Vu notes, you can use awk‘s intrinsic record splitting facilities to simplify life:

    processbody()
    {
        awk -F@ '
        { country_code[$2] = $1 }
        END {
            CITIZEN_COUNTRY_NAME = "INDIA"
            if (CITIZEN_COUNTRY_NAME in country_code) {
                value = country_code[CITIZEN_COUNTRY_NAME]
            } else {
                value = "null"
            }
            print "found " value " for country name " CITIZEN_COUNTRY_NAME
        } ' /tmp/country_codes.config
    }
    
    # Main program starts here
    processbody
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the exact equivalent (not functional) of this vb.net code in
I am running the exact same code in a WP7 application and a C#
On one hand, this problem is tough because I have the same exact code
I have this exact issue ASP.net can’t update page from event handler and it's
I know this exact question was asked here , but the answer didn't work
This is driving me nuts. I believe I asked this exact same question, but
I swear, I have this exact thing working on another page. I'm such a
This is an exact duplicate of: IE6 issues with transparent PNGs Firefox: IE 6:
This question is an exact duplicate of: Why generate long serialVersionUID instead of a
THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO sql and

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.