linux使用shell 进行文件数据的读取与排序

linux使用shell 进行文件数据的读取与排序,第1张

概述#!/bin/bashdeclare -a usernamedeclare -a sexdeclare -a usercodedeclare -a userpathi=0# scan data from keyboard or pipe# cat ../test | while read linefor line in `cat ../test`;do index=
#!/bin/bashdeclare -a usernamedeclare -a sexdeclare -a usercodedeclare -a userpathi=0# scan data from keyboard or pipe# cat ../test | while read linefor line in `cat ../test`;do    index=`expr $i / 4`    pos=`expr $i % 4`    if [ $pos -eq 0 ]    then        username[$index]=${line}    elif [ $pos -eq 1 ]    then        sex[$index]=${line}    elif [ $pos -eq 2 ]    then        usercode[$index]=${line}    else    userpath[$index]=${line}    fi    # echo $i,${usercode[$i]}    # echo ${username[$i]},${sex[$i]},${usercode[$i]},${userpath[$i]}    i=$(($i+1))donearr=(0 1 2 3 4 5 6 7 8 9)i=0j=0# sort it with ascendingwhile [ $i -lt 10 ]; do    j=$(($i+1))    while [ $j -lt 10 ] ; do        # echo ${usercode[${arr[$j]}]},${usercode[${arr[$i]}]}        if  [ ${usercode[${arr[$j]}]} -lt ${usercode[${arr[$i]}]} ]        then            tmp=${arr[$j]}            arr[$j]=${arr[$i]}            arr[$i]=$tmp        fi        j=$(($j+1))    done    i=$(($i+1))done# echo ${arr[@]}i=0while [ $i -lt 10 ]; do    index=${arr[$i]}    printf "%8s %6s %4s %10s\n" ${usercode[$index]},${username[$index]},${sex[$index]},${userpath[$index]}    i=$(($i+1))done
总结

以上是内存溢出为你收集整理的linux使用shell 进行文件数据的读取排序全部内容,希望文章能够帮你解决linux使用shell 进行文件数据的读取与排序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1024523.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存