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.
$1and$2should be quoted in the shell script parts. Also, I think the quoted script part should start on the same line asawk.