Wednesday, September 22, 2010

Linux Quick Hacks

Ascii Character Lister

To list printable characters and their ascii values, do the following:
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep '_\$'
To find the ascii code for a specific character (other than the space character, use $ in this example), do this:
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep '_\$'
Normal characters don't need and can't use the backslash, so to find the asci value of lower case 'd' you'd do this:
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep '_d'

To find the character corresponding to an ascii value, do this (example uses 100 as the ascii value):
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep ' 100'

Man pages formatted as text

Man pages look great on console screens, but piped to files or to browsers they quickly degenerate into cluttered conglomerations of reverse linefeeds and backspaces designed to simulate "bold" on your console screen. You get rid of the clutter by piping the output of man through thecol command. With no args, col blows off the reverse linefeeds but leaves the backspaces (^H). The command you want (using the ls man page as an example) is:
man ls | col -bx > myfile.txt
The preceding command writes the man page to myfile.txt, without backspaces (the -b) and with spaces substituted for tabs (-x).
more @ http://www.troubleshooters.com/linux/quickhacks.htm

No comments:

Post a Comment