Short Tip: Get file extension in Shell script

shell.png
The command basename is often used to extract the real file name without the file type specific file extension:

$ basename thisfile.txt .txt
thisfile

Now sometimes you need it the other way around, you might want to have the file extension. There are of course hundreds of ways to do so, but I found this one appealing since it also shows how the command awk works (which I should learn a bit better I think):

$ echo "thisfile.txt"|awk -F . '{print $NF}'
txt

The “-F” marks the delimiter, “$NF” means the last field generated. Seems to be a pretty straightforward tool.
On a total unrelated note I really like the source code post style of WordPress.

Short Tip: Write to syslog

shell.png
If you need to write something to syslog, Linux’ system logfile, you can do this by using logger:

logger Ready for xyz test

To check the result, run cat /var/log/messages:

Sep 17 17:14:48 localhost liquidat: Ready for xyz test

As you see the date, time and username are also included. In case you do this as root, the username will become logger.

Among the possible options of logger there are these two: -f will take a file as input instead of a message. The file content is parsed to the syslog entirely, so be easy on big files. The other one is -s: with that option the message will not only be posted to syslog but also to standard error.

Short Tip: Convert OGG screencasts to avi

shell.png
In case you have an OGG video file for example from a screencast and want to convert it to a avi file for dailymotion or youtube all you have to do is:

mencoder video.ogg -ovc lavc -oac mp3lame -o video.avi

I am aware that there are better methods: you could specify more flags for probably better quality. But this is seldom necessary when you are about to host these videos on some online service.

New Category: Short Tip

I just added a new category to this blog, “Short Tip”. In future it will be used for the really small but sometimes helpful things.

Usually I only cover stuff in this blog which is worth writing an entire article. But sometimes I come across small but very helpful tips or workarounds I would like to write down here to not forget them, but which are not long enough for an entire article. In the future these will be covered by the category Short Tip.

As you might have noticed all my articles follow a specific layout: there is the short summarize written in italic on top and flanked by a topic related image, and the rest of the article is sometimes parted by sub-headlines. And of course there is a lot of text.
And since i (quietly) introduced this new layout I’m quite pleased with it, however it makes it almost impossible to write really short things like the key bindings information. But this blog is, among other things, a place for me to remember important or useful or helpful information. Therefore I was wondering how to bring these together: layout on the one hand, short information on the other hand.

And I will take the direct way: tips won’t be written in the layout, they will just appear without anything else. Maybe I’ll keep the picture, but I’m not sure yet about that.

And if you just wonder why I do care so much about that topic and the style of writing: it is just too late for me 😉