perl -pe's/(^|\s)((\d?\d)?(\d)(\d)\d{5}|(\d?\d)?(\d)(\d)\d\d|\d{1,3})(?=\s|$)/$1.($3?" $3$4G":$4?" $4.$5G":$6?" $6$7M":$7?" $7.$8M":$2)/ge' #### /dev/dsk/c0t1d0s1 1.2G 814M 391M 68% /usr /dev/dsk/c0t1d0s3 245M 44M 176M 21% /var /dev/dsk/c0t1d0s0 424M 187M 194M 49% /home #### perl -pe's/(^|\s)((\d*?)\d)(\d)\d\d(\d{3})?(?=\s)/$1.($5&&" ").($3?" $2":"$2.$4").($5?"G":"M")/sge' #### $ echo \ 1234 12 12345 123456 1234567 12345678 123456789 | perl -pe'. . .' 1.2M 12 12M 123M 1.2G 12G 123G #### perl -pe's/(^|\s)((\d*?)\d)(\d)(\d)\d(\d{3})?(?=\s)/$1.($6&&" ").($3?" ".($2+($4>4)):$2+($4+($5>4))/10).($6?"G":"M")/ges' #### perl -pe's/((\d*?)\d)(\d)\d\d(\d{3})? /$1.($2?" ":".$3").($4?" G ":"M ")/ge' #### $ echo ' 1234 12 123 12345 123456 7654321 12345678 123456789 ' | perl -pe'... 1.2M 12 123 12 M 123 M 7.6 G 12 G 123 G #### perl -pe's!(^|\s)((\d*?)\d)(\d)\d\d((\d{3})*)(?=\s)!$"x($x=length$5).$1.($3?" $2":"$2.$4").qw(K M G T)[$x/3]!ges' #### $ echo \ 1234 1234567 123456789012 1234567890123 123456789012345 | perl ... 1.2K 1.2M 123G 1.2T 123T #### perl -pe's!\d{4,}(?=\s)!sprintf" "x($x=(-4+length$&)/3).($x*3%3?" %.0f":"%.1f").qw(M G T)[$x],$&/1024**int$x+1!ge' #### $ echo ' 321 4321 654321 87654321 9876543210 98765432101 987654321012 '|perl... 321 4.2M 639M 84G 9.2T 92T 920T #### perl -pe's!(^|\s)(\d{4,})(?=\s)!sprintf"$1%s".(($x=-4+length$2)%3?" %.0f":"%.1f").(qw(M G T))[$x/=3]," "x$x,$2/1024**int$x+1!ges'