2010-03-30

One-liners and why to get it harder than it could be

Since I've updated kernel and X server, my computer became slower... new "softwares" require new hardware to do the same things. This is a fact that always upset me. Anyway, I abandoned KDE (unusable... and half-mixed KDE3-4!) and installed WindowMaker. I also abandoned full graphics file-manager (avoid the loading of Qt libs and KDE services, being used to use Konqueror, uncomparable to Dolphin), tried lightweight Gtk file-managers but none satisfied me. I used midnight commander for a while and tried also gnu-git ... But now mainly I use simply the command line, in a simple xterm of course...

So it happens that something easy and fast with a filemanager becomes a little bit harder. But still the command line, with all GNU tools around and interpreters of languages like perl, is powerful.

When I download pictures from the cam, I need renaming them according to EXIF date; so I've created a script (exifrename.sh), which uses exif the extract the date and rename the object the way I want. I use it like this

exifrename.sh *.jpg |bash


The pipe is because the script outputs the commands rather than executing them (it could be useful to check everything's fine).

My cam creates a directory for each day, like NUMcanon where NUM is a number not related to the day. What I want is to copy just some days, not all, into the local hard disk and in the same time I want to strip the "canon" part. It would be easier maybe to copy the dirs and then rename them. But less fun for me. So what I do is

for el in 101 102 105 ; do mkdir $el ; 
pushd $el ;
cp -r /media/usbpen/dcim/${el}canon/* . ;
popd ; done


Ok not so funny but useful to... Recently I had to convert several scattered .doc (alas Microsoft stuff) into HTML, I've used this

find . -iname "*.doc" |
(
while read line;
do wvHtml "$line" "${line%.doc}.html ; done
)


As last example, a "oneliner" to read FASTA headers / sequences and sort them (just the header). Don't ask why, I've found the request on Yahoo Answer.

perl -e '%p=();
while(<>) {
if (/^>/) {
s/^>//; chomp;
foreach $v (split("\x01", $_)) {
$p{$v} = 1 if !exists $p{$v} ;
}
}
}
print join(" ", sort keys %p)' <fasta.txt


A perl guru can make surely better (and what about perl6?), anyway the solution worked .

Now we discover that there are things that can't be done simply by a graphics interface but... These examples are taken directly from the history of the shell; there are other two similar examples. The history has 1045 entries. Of these, 1039 are mainly simple commands like cd, rm, cp, ls, mkdir (and sometimes mount and umount). Actions that would have been a lot easier using a graphical file manager!

So the problem said at the beginning is back: I need keeping running few processes/programs. ... I'm going to hate the computer business, because I can't see a reason why to do the same thing I did before now I need more memory or a more powerful processor... or downgrading the software (meaning I should compile by myself a lot of codes since oldest packaged pre-compiled programs are already too recent, or there are too many dependencies issues I don't want to cope with!)

I hope things will be better, but looking around I see things indeed get worse: we can say Berlusconi is the winner, and this means there's no hope to change for Italy (it seems OT, but is not...).



Ah, the exifrename.sh code:
for el in "$@"; do
pathpart=$( dirname "$el" )
namepart=$( basename "$el" )
data=$( exif "$el" |egrep "Date and Time \(orig" \
|sed -e 's/^.*|\([0-9]\{4\}\):\([0-9][0-9]\):\([0-9][0-9]\) \([0-9][0-9]\):\([0-9][0-9]\):.*$/\1\2\3-\4\5/' )
echo "mv \"$el\" \"$pathpart/$data-$namepart\""
done

2010-03-26

Just to Begin

What should I write just to introduce myself or rather this blog? I really don't know, thus I won't try to be smart, cool or whatever. Basically I've nothing to say, so I can say everything, though in an English that could make someone shudder. And I'll begin from the very end. Few days ago (maybe already a week or more!) I was back from hospital. Recently I underwent a surgical operation, something like this (indeed, precisely it). Has this fact changed my view of life and universe? Nothing at all. Has this fact brought to me a new awareness about something? Maybe yes. Did I see a light, a bright tunnel, a whirl and hear a voice telling me my time is not come yet? No. Simply turned off for a while. No vision, no memory, no thought, no pain. Satori? I don't know but it was not unpleasant, and this is the outstanding fact. Unpleasant were the painful awakenings (two).

Will I talk about this in the blog? Not at all, luckly! It was just a way to begin and explain why I haven't been online for several days, a month and an half, more or less. Since January, 30, until a day in March. So you're wondering what this blog will be about... I think, but I am not sure, I will put in it words people can disregard, maybe opinions, maybe witticisms, maybe codes, ... ideas coming into my mind, without necessarily a logic tie, nor the claim to be interesting for a supposed audience. And of course without the promise for a perfect English... The only language I can write in correctly is Italian. Why doesn't I write in italian? Because I prefer to imagine a supposed larger audience.

That's all for this first post...