What's new

Approaches to blade inventory management

Wilkinson Sword Classic ⚔️(Germany) & 🕖7 O'Clock Yellows.
I keep mine in a small box. When I change blades I can't help but notice if I'm running low. So, before I run out I go online and order more. No agita.
:pipe:
 
Sure, it's nothing too complex:

Data is a single text file, with the following format:

Code:
1. Astra Superior Platinum (8) [2]
   Notes:

2. BIC Chrome Platinum (5) [1]
   Notes:

3. Bolzano Superinox (5) [1]
   Notes:

(X) is blade count, [Y] is number of tucks. Some data removed (the notes, mostly) for simplification

The script is a bit ugly... Here is the bulk of it. If you want the whole thing, feel free to ping me.

Code:
bcount () {
    awk -F'[.|)(]' -v patt="$brand" '$0 ~ patt\
        {printf "%s- %s %s\n", $2, $3, "blades in stock."}' "$file"
}

total=$( awk -F'[(|)]' '/\([0-9]+\)/ {sum+=$2} END\
        {print sum}' "$file" )

tucks=$( awk -F'[][]' '/[[0-9]+]/ {tsum+=$2} END\
        {print tsum}' "$file" )

[[ -z $opt ]] && usage && exit 1

case "$opt" in
    -b ) printf "%s\n" "$total blades in $tucks tucks."
        ;;
    -c) bcount
        ;;
    -n) printf "%s\n" "$total blades in stock."
        ;;
    -t) printf "%s\n" "$tucks tucks currently."
        ;;
    *) usage
        ;;
esac
Thanks for sharing this code!
I am a long time Linux user and I am amazed at how much you can get done with awk, sed and grep.
 
Top Bottom