设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Awk by Example--转载(5)

发布时间:2021-02-04 06:16 所属栏目:118 来源:网络整理
导读:function dotransfer(mybalance) { mybalance[0,$2] -= amount mybalance[curmonth,$3] += amount mybalance[curmonth,$3] += amount } { curmonth=monthdigit(substr($1,4,3)) amount=$7 #record all the categori

function dotransfer(mybalance) {
mybalance[0,$2] -= amount
mybalance[curmonth,$3] += amount
mybalance[curmonth,$3] += amount
}

{
    curmonth=monthdigit(substr($1,4,3))
    amount=$7
#record all the categories encountered
if ( $2?!= "-" )
    globcat[$2]="yes"
if ( $3?!= "-" )
    globcat[$3]="yes"

#tally up the transaction properly
if ( $2 == "-" ) {
    if ( $3 == "-" ) {
        print "Error: inc and exp fields are both blank!"
        exit 1
    } else {
        #this is income
        doincome(balance)
        if ( $5 == "Y" )
            doincome(balance2)
    }
} else if ( $3 == "-" ) {
    #this is an expense 
    doexpense(balance)
    if ( $5 == "Y" ) 
        doexpense(balance2)
} else {
    #this is a transfer
    dotransfer(balance)
    if ( $5 == "Y" ) 
        dotransfer(balance2)
}                        

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读