I've got the following command which is giving me the size in bytes of a bunch of folders in my hadoop cluster:
$ hdfs dfs -du -s /foo/bar/*tobedeleted | sort -r -k 1 -g | awk '{print $1, $3}'
31641789771845 /foo/bar/card_dim_h_tobedeleted
22541622495592 /foo/bar/transaction_item_fct_tobedeleted
3174354180367 /foo/bar/card_dim_h_new_tobedeleted
2336463389768 /foo/bar/hshd_loyalty_seg_tobedeleted
1238268384713 /foo/bar/prod_dim_h_tobedeleted
652639933614 /foo/bar/promo_item_fct_tobedeleted
490394392674 /foo/bar/card_dim_c_tobedeleted
365312782231 /foo/bar/ch_contact_offer_alc_fct_tobedeleted
218694228546 /foo/bar/prod_dim_h_new_tobedeleted
197884747070 /foo/bar/card_dim_h_test_tobedeleted
178553987067 /foo/bar/offer_dim_h_tobedeleted
124005189706 /foo/bar/promo_dim_h_tobedeleted
94380212623 /foo/bar/offer_tier_dtl_h_tobedeleted
91109144322 /foo/bar/ch_contact_offer_dlv_fct_tobedeleted
54487330914 /foo/bar/ch_contact_event_dlv_fct_tobedeleted
What I'd like to is format those numbers with GB/TB suffixes. I know I can use du -h
to format them but once I do that the sort command doesn't work.
I know I can do something like this:
$ hdfs dfs -du -s /foo/bar/*tobedeleted | sort -r -k 1 -g | awk '{print $1, $3}' | awk '{total = $1 / 1024 /1024 / 1024 / 1024; print total "TB", $2}'
28.778TB /foo/bar/card_dim_h_tobedeleted
20.5015TB /foo/bar/transaction_item_fct_tobedeleted
2.88706TB /foo/bar/card_dim_h_new_tobedeleted
2.125TB /foo/bar/hshd_loyalty_seg_tobedeleted
1.1262TB /foo/bar/prod_dim_h_tobedeleted
0.593573TB /foo/bar/promo_item_fct_tobedeleted
0.446011TB /foo/bar/card_dim_c_tobedeleted
0.33225TB /foo/bar/ch_contact_offer_alc_fct_tobedeleted
0.198901TB /foo/bar/prod_dim_h_new_tobedeleted
0.179975TB /foo/bar/card_dim_h_test_tobedeleted
0.162394TB /foo/bar/offer_dim_h_tobedeleted
0.112782TB /foo/bar/promo_dim_h_tobedeleted
0.0858383TB /foo/bar/offer_tier_dtl_h_tobedeleted
0.0828633TB /foo/bar/ch_contact_offer_dlv_fct_tobedeleted
0.0495559TB /foo/bar/ch_contact_event_dlv_fct_tobedeleted
but that's prints everything as TB which isn't what I wanted. Probably I can put some clever if...then...else logic into that last awk command to do what I want but I'm hoping there's a simple formatting option I don't know about that will do what I want.