[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Impossible perl one-liner?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok, here's probably a simple one -- I just can't get my head around it. :)

On Solaris, when I use "df -k" the sizes listed are in terms of KBytes.
I'm trying to come up with a simple perl one-liner to do one of two things
to make a quick scan of the list a bit easier to 'grok':
1: Add a comman "," between every third digit (1234567 -> 1,234,567)
2: Convert from KBytes to MBytes or GBytes by dividing by 1024 or 1024^2.

For #1, I couldn't get a perl one-liner could do multiple 'inserts' of
commas, especially when counting from the right-most digit and progressing
left.

I was trying this to achieve #2:
# echo leading text 1234567 trailing text | perl -pe 's/([0-9]+)/$1\/1024/g'
But that just returned:
leading text 1234567/1024 trailing text

I tried inserting the "eval" function, but couldn't get it to work...

So, anyone else got an idea?

Dan

P.s. I might end up writing a small script that uses more perl bruit force
but I thought a one-liner would be cleaner. :)

- - - - -
"I do not fear computer,
I fear the lack of them."
 -- Isaac Asimov
GPG fingerprint:9EE8 ABAE 10D3 0B55 C536  E17A 3620 4DCA A533 19BF

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCOLixNiBNyqUzGb8RAtmlAJ0VFzTy+fj38kcWPBWOPU8wa+bZcwCeIlg8
2UIZc0C8cnca4/a5/te2IvU=
=EWyj
-----END PGP SIGNATURE-----