Skip to content

Instantly share code, notes, and snippets.

@captin411
Created April 10, 2011 05:14
Show Gist options
  • Save captin411/912068 to your computer and use it in GitHub Desktop.
Save captin411/912068 to your computer and use it in GitHub Desktop.
shell function to provide "smart concatenation" to switch between cat zcat and bzcat as needed
# "smart cat" -- and an awesome acronym
# shell function which will try and use
# zcat or bzcat on the filename if provided
# add to your .bash_profile or whatever
# example: scat file1.txt file2.gz file3.bz2 | grep "something useful"
scat()
{
for FILE in $@; do
MIME=$(file -bi $FILE)
case $MIME in
"application/x-gzip")
zcat $FILE
;;
"application/x-bzip2")
bzcat $FILE
;;
*)
cat $FILE
;;
esac
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment