Hello,
I use Bash shell and I will be very much appreciated all of your help.
I have a lot of records in the flat file, called "Employees." Let's say a sample of three records ->
1001:JOHNSON:ROBERT J:90:70:85:80
1002:ROBERTS:JANE C:80:82:87:88
1004:VILLANUEVA:JEANNETTE K:90:92:94:92
Let's say that the last 4 fields are the test score and I have already completed all necessary computation. The average score of Johnson will be 81, which is equivalent to B. Roberts has an average of 84, which will be equivalent to B and Villanueva has an average of 92, which is equivalent to A.
The variable names for average is "saverage" and the letter grade is "ltr".
I have already completed the program that will print employee ID, Name, Last Name, saverage and ltr. The variables "saverage" and "ltr" are not in the employee file.
When I use the echo command -> echo "$id $fname $lname $saverage $ltr", I got the print out. However, the alignment looks terrible. I got something like this:
SN# Name Last Name Average Ltr
1001 ROBERT JOHNSON 81 B
1002 JANE ROBERTS 84 B
1003 JEANNETTE VILLANUEVA 92 A
Look like the spacing is automatic after running the echo command.
My question is very simple. How can I align the print out to correct my current spacing issue? The awk command might be the best but I do not think I can use the syntax like this:
awk -F: '{printf "%-5s %-12s %s %d %s\n",$1, $3, $2, $saverage, $ltr}' employees.
If some commands like this work, I know that I can solve the alignment problem. Since there are no field "average" and "letter grade" in the employees file.
All suggestions are welcome. I do not know much about the Unix command. I will be very much appreciated all of your help. Thank you again.
I use Bash shell and I will be very much appreciated all of your help.
I have a lot of records in the flat file, called "Employees." Let's say a sample of three records ->
1001:JOHNSON:ROBERT J:90:70:85:80
1002:ROBERTS:JANE C:80:82:87:88
1004:VILLANUEVA:JEANNETTE K:90:92:94:92
Let's say that the last 4 fields are the test score and I have already completed all necessary computation. The average score of Johnson will be 81, which is equivalent to B. Roberts has an average of 84, which will be equivalent to B and Villanueva has an average of 92, which is equivalent to A.
The variable names for average is "saverage" and the letter grade is "ltr".
I have already completed the program that will print employee ID, Name, Last Name, saverage and ltr. The variables "saverage" and "ltr" are not in the employee file.
When I use the echo command -> echo "$id $fname $lname $saverage $ltr", I got the print out. However, the alignment looks terrible. I got something like this:
SN# Name Last Name Average Ltr
1001 ROBERT JOHNSON 81 B
1002 JANE ROBERTS 84 B
1003 JEANNETTE VILLANUEVA 92 A
Look like the spacing is automatic after running the echo command.
My question is very simple. How can I align the print out to correct my current spacing issue? The awk command might be the best but I do not think I can use the syntax like this:
awk -F: '{printf "%-5s %-12s %s %d %s\n",$1, $3, $2, $saverage, $ltr}' employees.
If some commands like this work, I know that I can solve the alignment problem. Since there are no field "average" and "letter grade" in the employees file.
All suggestions are welcome. I do not know much about the Unix command. I will be very much appreciated all of your help. Thank you again.