Created
April 10, 2011 05:14
-
-
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
This file contains 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
# "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