#!/usr/bin/php
<?php

# Dieses Script sortiert /etc/passwd nach ID nummern und gruppiert nach tausender-IDs
# ACHTUNG! GANZ WICHTIG! Die Ausgabe dieses Scripts nicht per shell-redirect in /etc/passwd speichern! Aus irgendeinem Grund zerstört das die Datei!

$ary = array();

$passwd = file('/etc/passwd');
foreach ($passwd as $line) {
	$line = trim($line);
	if (($line == '') || ($line[0] == '#')) continue;

	$bry = explode(':', $line);
	$ary[$bry[2]] = $line;
}

ksort($ary);

$prev_n = -1;
foreach ($ary as $n => $line) {
	$this_n = floor($n / 1000);
	if (($prev_n != -1) && ($prev_n != $this_n))  echo "\n";
	echo "$line\n";
	$prev_n = $this_n;
}

