Sample Header Ad - 728x90

Trying to sort in alphabetical order of last name but needs to be formatted ID, first name, last name

0 votes
2 answers
140 views
No matter what I try with cut, awk, sed, or grep, it orders by ID first only then last name then first name when it should go in order of last name so it instead should look like f132b02: Kiara Acevedo f132a01: Caleb Barn but instead it orders it by ID and not alphabetical last name and output looks like this f132a01: Barn, Caleb f132b02: Acevedo, Kiara the information from the folder I'm retrieving the information is extracted from "~/Homework4/etc/passwd" and is trying to order the IDs below f132a01:Barn Caleb f132a02:Casey Nathan f132a03:Sanchez Ana f132a04:Thomas Jeff f132a05:Cavhill Jared f132b01:Johnson Andrew f132b02:Acevedo Kiara f132b03:Felaccio Steven f132b05:Blotner Sam f132b06:Pereira Brian The code I've been trying is down below: INPUT: cut -d: -f1,5 /etc/passwd | grep f132 | \ username, first name, and last name sed -E 's/(.*), (.*) (.*)/\1 \2 \3/' | \ sort -k3 echo count=$(cut -d: -f1,5 /etc/passwd | grep f132 | wc -l) echo "Number of students in the class: $count" OUTPUT: f132a01:Barn Caleb f132a02:Casey Nathan f132a03:Sanchez Ana f132a04:Thomas Jeff f132a05:Cavhill Jared f132b01:Johnson Andrew f132b02:Acevedo Kiara f132b03:Felaccio Steven f132b05:Blotner Sam f132b06:Pereira Brian
Asked by Natasha Shorrock (5 rep)
Sep 29, 2024, 09:15 PM
Last activity: Oct 7, 2024, 08:05 PM