Created
April 7, 2025 06:20
-
-
Save yeiichi/8ad15b0d1fdcacbac295efda62ecb146 to your computer and use it in GitHub Desktop.
sed & awk for gzip-ed text files.
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
#!/usr/bin/env zsh | |
# sed & awk for gzip-ed text files. | |
# The `zsmartcat` function reads the contents of a file, but it intelligently | |
# handles files that are either: | |
# 1. Gzip-compressed files (e.g., `.gz` files). | |
# 2. Regular text files (uncompressed files). | |
# The function decides whether to use `zcat` (to extract and display | |
# a gzip-compressed file) or the standard `cat` command (to display | |
# an uncompressed text file), based on the file type. | |
zsmartcat() { | |
if file "$1" | grep -q 'gzip compressed'; then | |
zcat "$1" | |
else | |
cat "$1" | |
fi | |
} | |
zawk() { | |
zcat "$1" | awk "${@:2}" | |
} | |
# Directory sed a gzip-ed text file. | |
zsed() { | |
zcat "$1" | sed "${@:2}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment