Hi I need to do this: Develop an AWK program that reads /etc/passwd and prints the names of those users having the same GID in the form GID name1 name2.
I was looking at this post on stackoverflow trying to develop a solution: awk + How do I find duplicates in a column?
The solution there kind of worked but was incomplete and was not formatted correctly.
I found this code on the Internet but can not get it to run:
awk -F: '{print $4}' /etc/passwd | sort | uniq -d > output.txt
awk -F: {kount[$4]++}
END{for {$1 in kount[$4]}}
printf("%d %s", $4, $1) output.txt
It is obvious it has some syntax problems with mixing the bash and awk code. I split it into two programs, a bash script and an awk script. The bash one works correctly it contains:
awk -F: '{print $4}' /etc/passwd | sort | uniq -d > output.txt
That program works correctly and gives me a file output.txt that contains the numbers 65534 and 7 which is correct.
I then tried writing the awk program to process that file and it looks like this:
BEGIN{
FS=":"
}
{a[$4]++}
END{
for {$1 in a[$4]}
{printf "%d %s", $4, $1}
}
and that doesn't work. I feel like I am really close but can't quite nail down the solution, any help would would much appreciated! Thanks in advance!