I found myself editing a configuration file (multiple actually) at work today and ran into an issue. The config file looked similar to:
Var_1=A Var_2=B Var_3=C ... Var_146=ABC Var_147=ABD
As it happened I needed to remove one of the lines at position 23. The program that reads/uses these config files has an issue if there is a break in the sequence. So after removing the line with “Var_23″ I needed to shift all of the numbers in following lines down by 1. Here is how I accomplished that.
In vim I put my cursor on the 24 in the line that now follows the “Var_22″ line and performed the following commands:
qa CTRL-X j q 125@a
Here is what happened broken down by line:
1: Here I am recording a macro (q) with the name or identifier of ‘a’. Note you will probably see some indication in the last line that you are in “recording” mode.
2: CTRL-X decrements the number under the cursor. Since I am on the 24 that decrements it to 23.
3: I move down 1 line and now the cursor is on the 25 in the next line.
4: I quit recording the macro. I know have a named (a) macro that includes the commands “decrement the number under the cursor and move down one row”.
5: I perform that named (a) macro 125 times. Now realistically I only needed to do it 123 times. It didn’t seem to matter that I used 125 but YMMV. The first line after the last line I wanted to change was a blank line so I assume the macro quit when the CTRL-X failed. You are probably better off using the exact number.
And there you have it. I successfully renumbered all of the variables below the line I deleted to be in sequence.

Tags: automation, configuration, replace, Shell, variable, vi
I work with long lists and WinSQL a lot. I always find myself wishing these long lists had commas at the end for pasting into a SQL where clause using “IN” for the list. This can be accomplished in one of two ways.
From the command line:
sed "s/$/,/g" <FILENAME>
I usually pipe the output there to a new file.
In vi (from command mode):
:%s/$/,/g
The “%” says to perfom the substitution on the whole file. In both cases we are doing a substitution of “$” (the end of the line) with a “,”.
Tags: automation, replace, sed, substitute, vi
If you use Transmission this little python script will start all of your downloads when your screensaver kicks on and pause them when it turns off, i.e. you are at your terminal.
#!/usr/bin/env python import dbus, urllib from dbus.mainloop.glib import DBusGMainLoop START_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-start" STOP_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-stop" DBusGMainLoop(set_as_default=True) sess=dbus.SessionBus() def sig(screensaverActive): if screensaverActive: data = urllib.urlopen(START_TORRENTS).read() else: data = urllib.urlopen(STOP_TORRENTS).read() sess.add_signal_receiver(sig, 'ActiveChanged','org.gnome.ScreenSaver') import gobject loop = gobject.MainLoop() loop.run()via I can’t find it at the moment but I will update once I get the link.
![]()
UPDATE:
I found my source here. The comments also include a patch for throttling the app rather than outright pausing everything.
SECURITY: I should point out, as mentioned in this comment, the RPC for Transmission will allow a nefarious person to control your application with a web page that includes elements like:
<img src="http://localhost:9091/transmission/rpc?method=torrent-stop">It is assumed that most (all?) other RPC calls for the web interface of Transmission could be called the same way. This is a fairly large security hole and I would suggest using a password on the Transmission web interface if you enable it. Though if you do that would render this tip pretty much useless.
Tags: automation, bittorrent, python, rpc, security