-5

次のような形式で、UIDとユーザー名のレポートを作成したいと思います。

9142   jdoe
9158   jsmith
75488  msteel

などなど

Unixの「id」コマンドから、システム上で次のような結果が得られます。

% id jdoe
uid=9142(jdoe) gid=101(users) groups=101(users)

また、ユーザー名が存在しない場合:

% id asdasdasd
id: asdasdasd: No such user

結果を次のようにしたいと思います(存在しないUIDの代わりにダッシュを使用):

----   asdasdasd
9142   jdoe
9158   jsmith
75488  msteel

あなたの助けは大歓迎です!ありがとう!

4

2 に答える 2

1

それはきれいではありませんが、:

sed -e 's/^uid=//;s/).*//;s/(/ /;s/^id:/----/;s/:.*//' | column -t

出力例:

(id; id root; id daemon; id foobar ) 2>&1 \
| sed -e 's/^uid=//;s/).*//;s/(/ /;s/^id:/----/;s/:.*//' \
| column -t

501   atomlinson
0     root
1     daemon
----  foobar
于 2012-11-28T05:37:11.053 に答える
1
id $1 > temp
if [ $? -eq 0 ]
then
    cat temp | awk -F' ' '{print $1}'|awk -F'=' '{print $2}'|sed 's/(/ /g'|sed 's/)//g' >> output.txt
else
    echo "------" $1 >> output.txt
fi
rm temp
于 2012-11-28T10:19:38.030 に答える