1

I received an error stating: "line 32 (final line): syntax error: unexpected end of file". I couldn't find the source of the error.

First input for the script: Input file name

Second input for the script: Employee name

Second column of the input file: Employee name

Fifth column of the input file: Salary

Sixth column of the input file: Date of joining



Below is my script:

# Check whether or not the command has two arguments

if [ $# -ne 2 ]; then

   echo "You must enter 2 arguments!\n"

   echo "Application is now exiting..."

   exit

fi



# Check whether or not the employee name supplied by the user is available in the input file

awk -v employee_name=$2 -v is_employee_available=0 -v year=0 -v new_salary=0 

'BEGIN{FS="|"}

{

   if(employee_name == $2) {

      is_employee_available=1;

      year=strtonum(substr($6,8,11));

      if(year==1990) 

         new_salary=$5+2000;     

      else if(year==1991) 

         new_salary=$5+1500; 

      else if(year==1992) 

         new_salary=$5+1000; 

      else if(year>1992) 

         new_salary=$5+500;   

      else 

         print "Invalid year of joining!";    

   }

}

END

{ 

   if(is_employee_available==0)

      print "The provided employee does not exist!"; 

}' $1

Thank you.

2
  • Not necessarily relevant, but the $1 and $2 should be quoted in the shell script parts. Also, I think the quoted script part should start on the same line as awk. Commented Oct 6, 2017 at 4:06
  • @Chris Yeah, thank you for advising me the best practice. Commented Oct 6, 2017 at 6:19

1 Answer 1

1
awk -v employee_name=$2 -v is_employee_available=0 -v year=0 -v new_salary=0 

'BEGIN{FS="|"}
^
Because of this

To

awk -v employee_name="$2" -v is_employee_available="0" -v year="0" -v new_salary="0" '
BEGIN{FS="|"}

OR

awk -v employee_name="$2" -v is_employee_available="0" -v year="0" -v new_salary="0" \
\
'BEGIN{FS="|"}

and

(with this you will get : END blocks must have an action part)

END

{

To

END{

OR

END\
\
{ 

and ( quoting is good practice )

}' $1

To

}' "$1"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help. I solved the problem. I really appreciate your effort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.