metalx1000

Sort and Rename Comcast Bill PDFs by Billing Date

Jul 23rd, 2025
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2025  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation version 3 of the License.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18.  
  19. # This will sort/rename Comcast Bill PDFs based on the "Billing Date" in the PDF
  20.  
  21. for pdf in *.pdf; do
  22.   month="$(pdfgrep -A 1 'Billing Date' "$pdf" | tail -n1 | awk '{print $5}')"
  23.   month="$(date -d "$month 1 2022" +%m)"
  24.   year="$(pdfgrep -A 1 'Billing Date' "$pdf" | tail -n1 | awk '{print $7}')"
  25.  
  26.   mv -v "$pdf" "Comcast Statement ${year}-${month}.pdf"
  27. done
  28.  
Advertisement
Add Comment
Please, Sign In to add comment