Skip to content

Instantly share code, notes, and snippets.

@asakura42
Last active September 2, 2021 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asakura42/c1ffb6082e4ca47e3a51640633a3e7bd to your computer and use it in GitHub Desktop.
Save asakura42/c1ffb6082e4ca47e3a51640633a3e7bd to your computer and use it in GitHub Desktop.
catt
#!/bin/sh
case "$1" in
*.pdf)
exec pdftotext -layout "$1" -
;;
*.xl[ast][xmt])
exec unzip -qc "$1" *.xml | sed -e 's/<\/[vft]>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*.xlsb)
unzip -qc "$1" *.bin | strings -e l
;;
*.xl[wsrta])
exec strings "$1"
;;
*.do[ct])
exec catdoc -m160 "$1"
;;
*.do[tc][xm])
exec unzip -qc "$1" word/document.xml | sed -e 's/<\/w:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*.p[po]t)
exec strings -d "$1"
;;
*.p[po]t[xm])
exec unzip -qc "$1" ppt/slides/*.xml | sed -e 's/<\/a:t>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*.html)
exec cat "$1" | w3m -T text/html -dump -cols 250
;;
*.epub)
exec unzip -qc "$1" *.*htm* | w3m -T text/html -dump -cols 250
;;
*.chm)
exec 7z e -r -so "$1" *.*htm* | w3m -T text/html -dump -cols 250
;;
*)
case $(file "$1") in
*Zstandard*)
exec pzstd -cdq "$1"
;;
*)
exec cat "$1"
;;
esac
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment