shell练习1

题目 把ls -l 的输出按照属主分类,打印每个属住的文件名

ls -l |sed -n '2,$p'| awk '
{hash[$3]=hash[$3]"""\n\t"$9} 
END{
for (user in hash) 
    print user"\n", hash[user]"\n"
}'

主要是这个hash[$3]=hash[$3]"""\n\t"$9,awk字符串拼接不能用+,用两个双引号

另一种实现 是浮夸写的

ls -l | sed -n '2,$p' | awk '{print $3,$9}'| sort | awk '
$1==name {
print "\t",$2
}
$1!=name{
name=$1;
print $1;print "\t" $2
}'

 

posted @ 2013-06-20 13:32  sunsweet  阅读(165)  评论(0编辑  收藏  举报