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

  • Home
  • SEARCH
  • 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 8745347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:59:34+00:00 2026-06-13T11:59:34+00:00

the script was working. I added some comments and renamed it then submitted it.

  • 0

the script was working. I added some comments and renamed it then submitted it. today my instructor told me it doesnt work and give me the error of awk 1 unexpected character '.'
the script is supposed to read a name in command line and return the student information for the name back.
right now I checked it and surprisingly it gives me the error.
I should run it by the command like this:

scriptName -v name="aname" -f filename

what is this problem and which part of my code make it?

#!/usr/bin/awk
BEGIN{
tmp=name;
nameIsValid;
if (name && tolower(name) eq ~/^[a-z]+$/ )
{

    inputName=tolower(name)
    nameIsValid++;
}
else
{
    print "you have not entered the student name"
    printf "Enter the student's name: "
    getline inputName < "-"
    tmp=inputName;
    if (tolower(inputName) eq ~/^[a-z]+$/)
    {
        tmpName=inputName
        nameIsValid++
    }
    else
    {
    print "Enter a valid name!"
    exit
    }
}
inputName=tolower(inputName)
FS=":"
   }
   {
if($1=="Student Number")
{
    split ($0,header,FS)    
}
if ($1 ~/^[0-9]+$/ && length($1)==8)
{
    split($2,names," ")
    if (tolower(names[1]) == inputName || tolower(names[2])==inputName )
    {
        counter++
            for (i=1;i<=NF;i++)
            {
                printf"%s:%s ",header[i], $i

            }

            printf "\n"

    }
}
   }
   END{
   if (counter == 0 && nameIsValid)
   {
 printf "There is no record for the %-10s\n" , tmp 
   }
   }
  • 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-06-13T11:59:35+00:00Added an answer on June 13, 2026 at 11:59 am

    Here are the steps to fix the script:

    1. Get rid of all those spurious NULL statements (trailing semi-colons at the end of lines).
    2. Get rid of the unset variable eq (it is NOT an equality operator!) from all of your comparions.
    3. Cleanup the indenting.
    4. Get rid of that first non-functional nameIsValid; statement.
    5. Change printf "\n" to the simpler print "".
    6. Get rid of the useless ,FS arg to split().
    7. Change name && tolower(name) ~ /^[a-z]+$/ to just the second part of that condition since if that matches then of course name is populated.
    8. Get rid of all of those tolower()s and use character classes instead of explicit a-z ranges.
    9. Get rid of the tmp variable.
    10. Simplify your BEGIN logic.
    11. Get rid of the unnecessary nameIsValid variable completely.
    12. Make the awk body a bit more awk-like

    And here’s the result (untested since no sample input/output posted):

    BEGIN {
        if (name !~ /^[[:alpha:]]+$/ ) {
            print "you have not entered the student name"
            printf "Enter the student's name: "
            getline name < "-"
        }
    
        if (name ~ /^[[:alpha:]]+$/) {
            inputName=tolower(name)
            FS=":"
        }
        else {
            print "Enter a valid name!"
            exit
        }
    }
    
    $1=="Student Number" { split ($0,header) }
    
    $1 ~ /^[[:digit:]]+$/ && length($1)==8 {
    
            split(tolower($2),names," ")
    
            if (names[1]==inputName || names[2]==inputName ) {
                counter++
                for (i=1;i<=NF;i++) {
                    printf "%s:%s ",header[i], $i
                }
                print ""
            }
        }
    }
    
    END {
        if (counter == 0 && inputName) {
            printf "There is no record for the %-10s\n" , name
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a PHP script that updates some tracking numbers based on an
Today when I was working on some javascript in an Asp.NET page, I did
I´m working with Eclipse 3.4.2 with PDT. I´ve added some libraries in the applications
I have a script working well for creating ad hoc iPhone builds. I can
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I've just about got the jPicker script working flawlessly in my app. However, the
So I have my upload script working just fine, but now it's a matter
I am trying to get my session login script working and I had the
I have a working script from someone, there in is this line: this.event =
The following java-script is working fine (Jquery) $(document).ready(function(){ $('#c_area').load($('.m_top:first').attr('href')) }); $('.m_top').click( function(){ $(#myDiv).html('<img src=images/loading.gif

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.