All pastes #346615 Raw Edit

Untitled

public text v1 · immutable
#346615 ·published 2007-02-09 13:24 UTC
rendered paste body
#DESIRED OUTPUT (for conky):
 
#calmar@tuxli:~/bin> ./conky.awk ~/.mail/inbox
#F: mac@calmar.ws  S: subject
#F: calmar4        S: 44
#F: calmar5        S: 5 5 55
#F: calmar6        S: 6 6 6 6
 
#What actually works, now. I'm just not sure if there are smarter ways to achive that?
#scanning the From: and Subject: in the inbox file and printing them nicely formatted
 
#!/usr/bin/awk -f
 
BEGIN{ 
    z=0;
}
 
/^From:/ {
    from="";
    for(i=2;i<=NF;i++){ # I want $2..(until an item beginning with '<' )
        if (substr($i,0,1) != "<"){ # '<' is there when: name + email. then only name
            from = from " " $i;
        }
    }
    tmp = sprintf ("F:%-15s", substr(from, 0, 15));  # From:
}
 
/^Subject/ {
    subj="";
    for(i=2;i<=NF;i++){  # I want $2..NF, that's the way to go?
        subj = subj " " $i;
    }
    arry[z] = tmp sprintf (" S: %s", substr(subj,0,27)); # complete output
    z++
}
 
END{
    u=0
    while (u++ < 4){
        if (--z >= 0)
            print arry[z];
        else
            print
    }
}