Tag Archives: Free Software

GNU text utilities

I’ve already written that i like the GNU Textutils a lot. Today someone had the following problem: A textfile with words. It’s possible that a word is repeated a couple of times. He wants to generate a newfile without duplicate words. The solution is pretty simple:

sort words.txt | uniq > newfile.txt

a little hint for writing and testing a script

I noticed that most people think Vim sucks and they constantly perform the following keystrokes:

:wq
perl somefile.pl
vim somefile.pl

Here is the first trick, you don’t need to exit vim to perform a command. Simply type the following while you’re in vim:

:!perl somefile.pl

Offcourse, you don’t want to type the filename all the time, so you use the following:

:!perl %

Now, if you are using a different scripting language it might be more portable to make the file executable (chmod u+x) and make sure the Shebang points to the right interpreter. Your script would be something like the following then:

#!/usr/bin/env perl
use strict;
use warnings;
use Socket;

Now all you have to do is type the following in vim and your script will be executed:

:!%

I noticed that the :!% trick doesn’t work when your script is in your current working directory. This is how you can make it work:

:!./%

I also noticed that before you execute this command you always need to type :w to save the changes. To automate this i’ve added the following to my ~/.vimrc file:

map ,r :w<cr>:!./%</cr><cr>
</cr>

Now all i have to type is the following:

,r

For other tricks and hints you have to check out Vi-IMproved.org.

GNU text utilities

More and more i seem to recieve requests from people that need to manipulate some text files.
And they don’t feel like doing it manually. So here are some examples of how i used the
GNU text utilities:

I want to split the file below into one with the questions and one with the answers. This can be easily done:

Who is the manual.*I am
Who am i.*The manual
What was HLN's first #1 hit.*Power of love
Which News man is the oldest.*Huey
About how many months did it take to record Small World.*4
Who wrote Jacob's Ladder.*Bruce Hornsby
cut -d "." -f1 trivia.txt > questions.txt
cut -d "*" -f2 trivia.txt > answers.txt

I want to know how many times people have logged in. With last i recieve output like below.
I generate a top10 list:

xabre    pts/0        cable-213-132-14 Wed Jul  6 14:41   still logged in
veurm    pts/16       80.236.195.247   Wed Jul  6 14:28   still logged in
timvw    pts/6        ip-213-49-86-220 Wed Jul  6 14:21   still logged in
ward     pts/1        dd5768f62.access Wed Jul  6 14:04   still logged in
bokkerij pts/1        91.42-201-80.ads Wed Jul  6 13:57 - 14:00  (00:02)
cowke    pts/54       215-157.241.81.a Wed Jul  6 13:37    gone - no logout
mette    pts/51       ip-213-49-112-10 Wed Jul  6 13:36   still logged in
esumlu   pts/49       176.228-201-80.a Wed Jul  6 13:25   still logged in
veurm    pts/6        ip-213-49-84-129 Wed Jul  6 13:21 - 14:10  (00:49)
trooperz pts/6        160.148-136-217. Wed Jul  6 13:05 - 13:21  (00:15)
gunther  pts/40       d5153d0d9.access Wed Jul  6 12:28   still logged in
timvw    pts/34       ip-213-49-86-220 Wed Jul  6 11:02 - 14:21  (03:19)
last | cut -d " " -f1 | sort | uniq -c | sort -rn | head

I want to use this file to generate two files, one for small galleries (<10 photos) and one for large
galleries (>= 10 photos)


http://example.com/gallery1|Fishing|18

http://example.com/gallery2|Fishing|5

http://example.com/gallery3|Fishing|6

http://example.com/gallery4|Fishing|5

http://example.com/gallery5|Fishing|35

http://example.com/gallery6|Fishing|2

http://example.com/gallery7|Fishing|1

http://example.com/gallery8|Fishing|9
grep  -E "(.*?)\|[0-9]{1}$" galleries.txt > small.txt
grep -vE "(.*?)\|[0-9]{1}$" galleries.txt >large.txt

Getting started with CVS

I got an e-mail that asked me how to get started with CVS as quick as possible. The first time i got lost too. So i’ll give a quick summary how i did it (no p-server).

The repository will live on a debian machine in /home/users/timvw/services/cvs.

timvw@debian: apt-get install cvs # get the tools
timvw@debian: cvs -d /home/users/timvw/services/cvs init # create repository

On my windows machine i use TortoiseCVS. I want to make a module pecl that will contain all my pecl related code.

1. Configure TortoiseCVS to use the SSH.com client instead of the built-in Putty.

configure

2. Fill in the path to the SSH binary (tools tab).

configure

3. Create a directory that will hold the code (i choose pecl as name).

new directory

4. Create a module (Choose the directory you created and click right).

new module

5. Fill in the settings.

module settings

6. Hit Ok to initialise the module.

module init

7. Create a README file and add it to the module.

add file to module

add file to module

8. Add a comment message

add comment

9. Commit the changes

commit

10. Update your files (Other people have commited their changes).

update

11. Read The Fine Manual at http://cvsbook.red-bean.com/cvsbook.html

Configuring Mutt for GPG

Today i generated a PGP (Pretty Good Privacy) key for my e-mail address. I also configured my mailclient, mutt, for use with GnuPG. I copied a sample file i found on the net but always got an error message: sh: line 1: pgpewrap: command not found. It appears that /usr/lib/mutt/ is not in the path and therefore is not found. Here is the tweaked .muttrc part:

set pgp_decode_command="gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"
set pgp_verify_command="gpg --no-verbose --batch --output - --verify %s %f"
set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign \
--textmode %?a?-u %a? %f"
set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor \
--textmode --clearsign %?a?-u %a? %f"
set pgp_encrypt_only_command="/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt \
--textmode --armor --always-trust --encrypt-to 0xE38BE821 -- -r %r -- %f"
set pgp_encrypt_sign_command="/usr/lib/mutt/pgpewrap gpg --passphrase-fd 0 --batch --quiet --no-verbose \
--textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0xE38BE821 -- -r %r -- %f"
set pgp_import_command="gpg --no-verbose --import -v %f"
set pgp_export_command="gpg --no-verbose --export --armor %r"
set pgp_verify_key_command="gpg --no-verbose --batch --fingerprint --check-sigs %r"
set pgp_list_pubring_command="gpg --no-verbose --batch --with-colons --list-keys %r"
set pgp_list_secring_command="gpg --no-verbose --batch --with-colons --list-secret-keys %r"
set pgp_autosign=no
set pgp_sign_as=0xE38BE821
set pgp_replyencrypt=yes
set pgp_timeout=1800
set pgp_good_sign="^gpg: Good signature from"