Tag Archives: CLI

Perl Script – Text File to a Table

I could not find a utility to turn a delimited text file into an ASCII table. So I built a simple one in Perl. It builds on this work by preparing the data for it.

The user creates a file with some delimiter, such as a Comma-Separated Values file, and then runs it through the script. The table is sent to standard output, and the user can do what they want with it.

It is run as such:

perl TextFileToTable.pl [delimiter] [file to be read]

For instance:

perl TextFileToTable.pl \& data.txt

The order is important.

The code, in an archive.

Leave a comment

Filed under Computing, Content

Remapping Keys in X for Linux

I do not have any purpose for the Caps Lock key. So it remains useless in a prime real estate position. But I use an open-source operating system (GNU/Linux, xmonad GUI), which means that I can remap that key to do something useful. Here is how to remap the Caps Lock key to become a third Control key through your Linux terminal emulator:

xmodmap -e “remove lock = Caps_Lock”
xmodmap -e “add control = Caps_Lock”

Test it out now. Go open new tabs in Firefox with one hand without straining your fingers. Just press “Caps Lock (Now Control) + t”.



Now for some background on this. Start by entering this command into a terminal:

xev

With the pop-up box selected, Press and Release the Caps Lock key and then the left Control key. The keycode and the name associated with that keycode will be displayed for each of the keys will be displayed along with other information. Write it down.

Output from xev

Output from xev

Next, enter into the terminal:

xmodmap

This will display the information for which keys are acting as modifier keys. The two commands originally issued with the “-e” switch modified which keys act like modifiers. First, the key called “Caps_Lock” was removed from the “lock” function. We added it to the “control” function instead.

Modified xmodmap Output

Modified xmodmap Output

If you want to see every keycode assigned on your keyboard, enter the command:

xmodmap -pke

Between the output from that command and the functions of “xev”, you should be able to figure out the name of any key on the keyboard. This includes funky custom keys that are not standard.


If you mess something up, restart your computer with the mouse if you killed the keyboard, or just restart X with “Control + Alternate + Backspace” (Not Delete). This will reassign your keys to their default.

If you want this to stick between sessions, you will need to edit some files in your home directory. Check you “home” directory with:

ls -a | grep “\.”

If the “.profile” and “.Xmodmap” files are not listed, create them with a text editor as will be discussed:

Open up a text editor and have it open or create the file “.Xmodmap” in your home directory. Otherwise known as “/home/YOURUSERNAME/.Xmodmap”. Paste Xmodmap commands into there if it is new; at the end if there is stuff in this already existing file.

remove lock = Caps_Lock
add control = Caps_Lock

We removed the “xmodmap -e” because these commands are being run within the “.Xmodmap” file.

Save, and close. Now open the “.profile” document and drop this onto the end of it:

xmodmap $HOME/.Xmodmap

For those left-handed people who would prefer to have their mouse viewed as left-handed, and have the primary button on the right side of the mouse, enter this command:

xmodmap -e “pointer = 3 2 1”

This will switch the order of your primary and secondary click buttons. If you like this, paste “pointer = 3 2 1” into “.Xmodmap”, too.

Leave a comment

Filed under Computing, How-To

Image Magick Preservation

Image Magick takes care of all my image converting needs. It is a wonderful tool for saving important images from the rot that happens when you move images around that are stored with a compression-minded format.

Ever notice that your .JPG files get all gritty after some time? I sure do not like that. So I prefer to save things in the .PNG format. While the image file-size becomes larger, the quality does not decrease overtime. A trade-off I am willing to pay in this age of external hard-drives and Internet storage.

You can usually find Image Magick in your Linux repositories. If you cannot, or you run Windows, you can pick up binaries on the website at:

http://www.imagemagick.org/

There is a laundry list of commands and functions this program suite has. An excellent tool to have around for bash-scripting jobs.

I use this command on my Linux box to preserve my important files. I pack them all together into one directory, and then enter this into the terminal:

mogrify -format png *

It converts all files in the directory to .PNG files. Make sure you only have image files in there.

Additional help can be found here:

http://www.imagemagick.org/script/command-line-tools.php

Leave a comment

Filed under Computing, How-To