day1.sh

mail@pastecode.io avatar
unknown
sh
7 months ago
387 B
12
Indexable
Never
#!/bin/bash

sed -e 's+[A-Za-z]++'g | awk '{

    arg   = $1
    first = substr(arg, 1, 1)
    last  = substr(arg, length(arg), 1)

    if (length(debug) > 0) {
        printf("%s %s %s\n", arg, first, last)>"/dev/stderr"
    }

    calStr = sprintf("%s%s", first, last);
    calNum = 0 + calStr
    printf("%d\n", calNum);

    sum += calNum

} END { 

    print sum 

}' debug=$debug

Leave a Comment