3 ms·
Two nitpicks: grep by default returns lines that match, not files, you need the '-l' option; and you're passing the string "translated_files" to du instead of t
by icebraining 15y ago
Two nitpicks: grep by default returns lines that match, not files, you need the '-l' option; and you're passing the string "translated_files" to du instead of the actual files, you need just $translated_files instead of the echo.
And that breaks with files with spaces on them, which is a bane of shell scripts.
By the way, in Python:
import os
total_size = sum([os.path.getsize(filename) for filename in os.listdir('.')])
matches = [match for match in os.listdir('.') if "todavida no ha sido traducida" in open(match).read()]
translated_file_size = sum([os.path.getsize(filename) for filename in matches])
print "translated size: %dKB/%dKB %d" % (translated_file_size, total_size, translated_file_size / total_size)
- moonboots 15y agoGood catches The spaces in filenames can be handled by having grep and du communicate with null delimited strings instead of newline delimited, e.g. grep --files-with-matches --null "todavida..." * du --summarize --total --files-from=<($(echo $translated_file_size))