Created
July 25, 2023 21:15
-
-
Save Micrified/fdb6fbf969a35f73b25d909ecdf2559e to your computer and use it in GitHub Desktop.
Convert a Payslip to text format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# payslip2text: Convert <company> payslip(s) to text form | |
# awk: extract fields | |
PP='/^If undeliverable/ { printf "%s-%s\n", $8, $9 } | |
/^Gross Salary/ { print $3 }; | |
/^Contr.employer Health Ins/ { print $4 }; | |
/^Pension fund premium/ { print $4 }; | |
/^PAWW contribution/ { print $3 }; | |
/^Taxable wage/ { print $3 }; | |
/^Wage Tax/ { print $4 }; | |
/^Home work allowance/ { print $4 }; | |
/^Net Wages/ { print $3 }; | |
/^Premium Health Ins/ { print $4 }; | |
/^Payable Amount/ { print $3 }; | |
/^Bank transfer/ { print $4 }' | |
# sed: filter (rules semicolon delimited) | |
# 1. Strip decimals (European notation) | |
# 2. Replace commas with decimals (US notation) | |
# 3. Remove trailing minus sign (Payslip characteristic) | |
FF="s/\.//g;s/,/\./g;s/-$//g" | |
# process arguments (convert if needed) | |
echo "Date Gross Emp.Health.Ctr Pension.Prem PAWW.Ctr Taxable Tax WFH.Allow Net Health.Prem Payable Transferred" | |
for i | |
do | |
case $i in | |
*.pdf) buf=`pdftotext -q -raw $i - 2>/dev/null` ;; | |
*.txt) buf=`cat $i` ;; | |
*) echo "Warning: Skipping unsupported file-extension: $i" 1>&2; continue ;; | |
esac | |
[[ $? -eq 0 ]] && printf "%s" "${buf}" | awk "${PP}" | sed "${FF}" | xargs || \ | |
(echo "Error: Cannot process buffer for $i" 1>&2 && exit -1) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment