Thanks to stackoverflow for this one.
:g/^$/d will delete all blank lines in a file
Why? Because :g will execute a command on lines which match the regex and :d deletes :)
Thursday, January 27, 2011
Put the results of a command in the current vim buffer
:r will read a file into the current buffer in vim
:! will execute a command
You can use them together to read the results of a command and put them in the current buffer
:! will execute a command
You can use them together to read the results of a command and put them in the current buffer
e.g. :r ! ls -1 /home/user/directory | sort -r
Monday, January 24, 2011
Update Ubuntu Release from the command line
sudo apt-get install update-manager-core # may/may not be necessary
sudo do-release-upgrade
If there's no new release found and you think there should be, check /etc/update-manager/release-upgrades and change Prompt=lts to Prompt=normal if necessary
sudo do-release-upgrade
If there's no new release found and you think there should be, check /etc/update-manager/release-upgrades and change Prompt=lts to Prompt=normal if necessary
Wednesday, January 12, 2011
Reset Moinmoin password
I always forget this
moin account resetpw --name=username password
moin account resetpw --name=username password
Tuesday, January 11, 2011
Postgres Recovery
Postgres killed itself during a disk failure and while later trying to start it up I got messages along the lines of:
database system was interrupted; last known up at ...
database system was not properly shut down; automatic recovery in progress
redo starts at 309/3BA1EB48
record with zero length at 309/3C9F8ED8
redo done at 309/3C9F8EA8
last completed transaction was at log time ....
could not fdatasync log file 777, segment 60: Input/output error
startup process (PID 23142) was terminated by signal 6: Aborted
aborting startup due to startup process failure
On further investigation it sound like the transaction log was corrupted. This can be fixed with pg_resetxlog. This will clear the write ahead log and may result in some data loss or loss of integrity but when nothing else works it's a lifesaver. The documentation describes some follow up steps to ensure the integrity of data after postgres is starting properly.
You can do a dry run:
sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog -n /var/lib/postgresql/8.4/main
and if that indicates a new segment and there's no other option then you might as well reset with:
sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog /var/lib/postgresql/8.4/main
or
sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog -f /var/lib/postgresql/8.4/main
database system was interrupted; last known up at ...
database system was not properly shut down; automatic recovery in progress
redo starts at 309/3BA1EB48
record with zero length at 309/3C9F8ED8
redo done at 309/3C9F8EA8
last completed transaction was at log time ....
could not fdatasync log file 777, segment 60: Input/output error
startup process (PID 23142) was terminated by signal 6: Aborted
aborting startup due to startup process failure
On further investigation it sound like the transaction log was corrupted. This can be fixed with pg_resetxlog. This will clear the write ahead log and may result in some data loss or loss of integrity but when nothing else works it's a lifesaver. The documentation describes some follow up steps to ensure the integrity of data after postgres is starting properly.
You can do a dry run:
sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog -n /var/lib/postgresql/8.4/main
and if that indicates a new segment and there's no other option then you might as well reset with:
sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog /var/lib/postgresql/8.4/main
or
sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog -f /var/lib/postgresql/8.4/main
Friday, January 7, 2011
Pretty Print XML in Python
From the command line:
python -c "import xml.dom.minidom; xml = xml.dom.minidom.parse('myxmldoc.xml'); print xml.toprettyxml()"
python -c "import xml.dom.minidom; xml = xml.dom.minidom.parse('myxmldoc.xml'); print xml.toprettyxml()"
Subscribe to:
Posts (Atom)