Chinaunix
标题:
找出/etc/passwd id号最大的一行
[打印本页]
作者:
allen08pm
时间:
2014-09-04 15:23
标题:
找出/etc/passwd id号最大的一行
1、找出 /etc/passwd id号最大的一行
2、能不能只输出id号最大一行的用户名
作者:
ly5066113
时间:
2014-09-04 15:30
回复
1#
allen08pm
awk -F : '$3>id{user=$1;id=$3}END{print user}' /etc/passwd
作者:
allen08pm
时间:
2014-09-04 15:33
谢谢
回复
2#
ly5066113
作者:
Buring__
时间:
2014-09-04 16:02
awk -F: '{if(a<$3){a=$3;user=$1}}END{print user}' /etc/passwd
作者:
dn833
时间:
2014-09-04 16:23
sort -t : -nr -k 3 /etc/passwd|grep -Pom1 '(?<=^)[^:]+'
复制代码
作者:
reb00t
时间:
2014-09-04 16:42
<?php
$fp = file('/etc/passwd');
$max = 0;
foreach ($fp as $k => $v) {
$arr = explode(":",$v);
$max = $max<$arr[2]?$arr[2]:$max;
if($max == $arr[2]) $user = $arr[0];
}
echo $max."\n";
echo $user;
?>
结果:
500
nagios
复制代码
作者:
NOpuzzled
时间:
2014-09-04 17:07
#!/usr/bin/env python
# encoding: utf-8
num=[]
f = open('/etc/passwd')
ff=f.read().strip().split('\n')
for i in ff:
num.append(int(i.split(':')[2]))
print max(num)
f.close()
~
复制代码
作者:
zerostudy
时间:
2014-09-04 23:42
awk -F : '{max=$3>max?$3:max;a[$3]=$1}END{print a[max]}' /etc/passwd
复制代码
作者:
warlegtree
时间:
2014-09-11 17:37
本帖最后由 warlegtree 于 2014-09-11 17:39 编辑
cat /etc/passwd|sort -n|tail -n 1|awk -F: '{print $1}'
作者:
李满满
时间:
2014-09-11 20:36
学生党:飘过~
[oracle@orcl ~]$ awk 'BEGIN{FS=":";max=0}{if(max<=$3){max=$3;usr=$1}}END{print usr}' /etc/passwd
nfsnobody
作者:
yestreenstars
时间:
2014-09-11 22:10
民主党:飘过~
awk -F: '{a[b[$3]=$3]=$1}END{asort(b);print a[b[length(b)]]}' /etc/passwd
复制代码
作者:
Mao2003
时间:
2014-09-12 11:24
作者:
cncruyff
时间:
2014-09-12 14:06
写个perl的
perl -F":" -anl -e '$names{$F[2]}=$F[0];$big||=0;if($F[2]!=65534){$big= $big>$F[2]?$big
F[2]};END{print $names{$big}} ' /etc/passwd
作者:
baoersc
时间:
2014-09-12 14:12
本帖最后由 baoersc 于 2014-09-12 14:14 编辑
awk -F : '$3>id{user=$1;id=$3}END{print user}' /etc/passwd
二楼的比较简洁。
cat /etc/passwd | sort -t: -n -r -k3 | awk -F: 'NR==1{print $1}'
复制代码
作者:
251744647
时间:
2014-09-12 17:34
求最小id号:
awk -F: -v d=999999999 'd>$3{user=$1;d=$3}END{print user}' /etc/passwd
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2