Archive for the 'linux' Category

Sunday Tip Day: Convert a shapefile to text with linux

Never apologise for delayed posts… this is a Sunday Tip Day post, not a Thursday! Anyhow…

I just found a super little cross-platform utility that takes shapefiles and dumps them to a variety of text-based formats. Download it here, and simply unzip it to use it.

There isn’t much documentation, but basically your options are to download to gpx or spreadsheet. The following gives you a simple delimited text file with the coordinates and values from your attribute table:

./shp2text -–spreadsheet /path/to/your/shapefile.shp > /path/to/output.txt

Bob is indeed your mother’s brother.

Slightly belated Thursday Tip Day: Find and replace text in multiple files

Apologies for the delay- it’s been a roller-coaster week at Archaeogeek Towers due to family health issues. Hopefully it’s getting sorted now though.

In the process of preparing Portable GIS, I needed to change a string in multiple files of multiple formats within multiple folders. I looked at various windows- based options, most of which had a charge associated with them, but one of my colleagues suggested a linux approach.

“Sed” is the command that you need, found in most linux systems. In windows you can install it as part of the unxutils toolkit. The following command in linux works recursively through the folders in a root directory changing string1 for string2 (be careful with those single quotes if copy and pasting as wordpress likes to restyle them):

find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;

With a large number of files this might take some time to work (a usb stick took an hour to work through on my ubuntu server vm but maybe that’s not a fair benchmark).

Thursday Tip Day: On USB keys at the linux command line

How to mount a USB stick in Ubuntu server using the command prompt only:

Do a sudo tail -f /var/log/syslog and plug the usb drive in.
Look for lines like these:
Feb 18 12:58:32 shuchi kernel: [17192272.616000] sda: assuming drive cache: write through
Feb 18 12:58:32 shuchi kernel: [17192272.616000] sda: sda1

Make a directory in /media named usbdrive.
Mount it like this: sudo mount /dev/sda1 /media/usbdrive

To unmount before ejecting:
sudo umount /media/usbdrive

If you get a message saying that the device is busy you can find out what process is using it using with the fuser command, with the -u parameter to see which user it is:

fuser -u /media/usbdrive

This will give you a number which refers to a process, and a user, then run ps -A to list all the processes and see which one it is. If you need to kill that process (USE WITH CAUTION) then run:

sudo kill -9 yourprocessnumber

You should then be able to safely unmount your USB drive

Archaeogeek’s quick February round-up

February’s quick links:

Next Page »