Last active
September 14, 2015 17:15
-
-
Save Jan-Zeiseweis/d7c85da5bfdeca3bcbfa to your computer and use it in GitHub Desktop.
split and gzip bash script
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
#!/bin/bash -e | |
# usage: bash ./split_and_gzip.sh file.txt | |
FILE=$1 | |
LINES_PER_FILE=10000000 #10m | |
$(split -l $LINES_PER_FILE -d $FILE ${FILE}.) | |
FILES=${FILE}.* | |
for f in $FILES | |
do | |
echo "GZipping file $f ..." | |
number=$(echo $f | grep -oE "[[:digit:]]{1,}$") | |
filename="${FILE}.gz.${number}" | |
$(gzip $f -c > $filename) | |
$(rm $f) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment