Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

A Python script to generate the first digit distribution of the byte …

…count of any directory.
  • Loading branch information...
commit 16e11be244f833877e1a4feeac751f379831abaa 1 parent 9848726
@fweez fweez authored
Showing with 27 additions and 0 deletions.
  1. +27 −0 ben.py
View
27 ben.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+import os
+import subprocess
+
+# First, build up the results file. it'll have the form:
+# 110 vidioc-g-dv-preset.xml
+linecount_cmd = "for i in *; do find $i -execdir wc -c '{}' \; " + \
+ ">> results; done;"
+os.system(linecount_cmd)
+
+# Then figure out how many are in each bucket (linecount's initial digit)
+bucket_cmd = 'for i in `jot 9`; do egrep "^[ ]*$i" results| ' + \
+ 'wc -l; done > counts'
+os.system(bucket_cmd)
+
+# And how many total files there are...
+total_cmd = 'wc -l results'
+p = subprocess.Popen(total_cmd, stdout=subprocess.PIPE, shell=True)
+(total, _) = p.communicate()
+
+total = int(total.split()[0])
+
+for i in file('counts', 'r').readlines():
+ print 100 * (float(i) / total)
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.