Created
June 26, 2018 02:02
-
-
Save zachcb/4942c1e0b9fe424b9317693a431325ce to your computer and use it in GitHub Desktop.
Output file info and compress
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/sh | |
# Initializations | |
file=$1 | |
# wc command gets word, line, bytes count | |
# < input operator gets info from file so filename is not added | |
lines=$(wc -l < "$file") | |
words=$(wc -w < "$file") | |
characters=$(wc -m < "$file") | |
bytes=$(wc -c < "$file") | |
# Set file name plus out to be reused | |
outputfilename="$file.tar.xz" | |
outputfilesize=0 | |
# Compress input file, output | |
tar -cfJ $outputfilename $file | |
# set outfile bytes to new value | |
outputbytes=$(wc -c < "$outputfilename") | |
# Output bytes, use \ for spacing printf nicely, \n for new line | |
printf "Output \ | |
bytes $outputbytes \n | |
" | |
# Use variable inside string to get it to work | |
printf "$line \n $words \n $characters \n bytes $bytes \n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment