Weblog Home Web site's Home Clip art Search Clker.com – Available downloads RSS

Posts Tagged ‘find’

Discovering some of Linux Cow Powers: awk and bash

Tuesday, July 22nd, 2008

If you’ve never used linux you should give it a try. The simplest way is to install colinux with xming. If you feel its involved, just burn an ubuntu 8.04 bootable cd. It works out of the CD with almost all the every day used features without installtion, formating or any other extra work.

One of the cow powers that I use linux for, and didn’t find a way to do it using the windows shell is renaming a lot of files. I had around 3000 bmp files, their names were in the following format:

<word>-<volume>-<number>.bmp

and I wanted to rename them to

<word>-<number>.bmp

I couldn’t find a way to do this on windows except with writing a small pogram. On linux the solution is a program called awk, which can tokenize input strings, and write parts of them out. awk is a sophistiacated tool, and I usually use a very small subset of its features.

The solution was finally something similar to this:

find .bmp | awk -F- '{print "mv "$0" "$1"-"$3;}' | bash -v

The first part is running the find program to find all files with extension .bmp. The results are then piped as input to awk, instead of being written to the screen. awk is told that the field separator is ‘-’ using the -F parameter. A one statement awk program says print the words mv to issue commands to rename a file, then $0 for the full string before tokenizing, then the $1 for the first tokenized part, and $3 for the third tokenized part, skipping the second. So awk is being used to write the commands that we need to execute.

Those commands are then piped to bash, the bourne shell with the verbose flag on so that we can see the commands being executed.

A good practice when trying something like that is to pipe the results first to less, instead of bash. less is a program like more, which gives the user the ability to inspect whatever was piped to it and filp forward and backwords. It also includes some nice features like -N to show numbers, and searching for a word using the forward slash /  , with commands very similary to vim.

So the less version of the line whould be this:

find .bmp | awk -F- '{print "mv "$0" "$1"-"$3;}' | less

This is a very handy technique in renaming lots of files, or carrying batch operations on multiple files that I usually use.

Technorati Tags: , , , , , , ,

Adding picture to your wordpress weblog

Tuesday, November 20th, 2007

Human beings are visual creatures. Pictures and eye sight is the second important way by which humans learn after hearing. Adding pictures related to your post will help visitors get your point. Exactly like adding pictures in a presentation, which help people understand the description made by the presenter.

Adding pictures to your weblog post will also help attract attention to your article, and increase the time your visitors stay. Pictures breaks the boring lengthy text of an article and gives the reader a break in the middle.

An important factor is then how easy is it to a) find a picture ad b) add it to your weblog?

Clker.com offers a huge collection of high quality cliparts. All cliparts are tagged with relevant words making it very easy to search and find the exact picture you’re looking for. You can directly copy the HTML code and paste it in your weblog’s page. All pictures can be easily embedded in any HTML source.

By default, all pictures are floated to the left making the text wrap around it without wasting your weblog space. You can manually remove the float and allow the picture to occupy a full horizontal area as shown above.

Technorati Tags: , , , , , , , , , ,

11,247 spam comments
blocked by
Akismet