awk to the rescue

Some days back I got a collection of 100 Greatest Piano Works cd collection. The first thing I did was to rip the CD in flac and preserve a lossless copy of the disks. Then I converted those to ogg files (with oggenc ) so that I could take it in my iPod and listen at any time. The problem occurred at the final moment when I realized that the file names were really long and which would be very difficult to scan through my iPod (with Rockbox). The file name was in this format : %n – %a – %t.ogg  for example : For example :
“17 – Robert Schumann (1810-1856) – THE DAVIDSBÜNDLER DANCES, 18 CHARACTERISTIC PIECES, OP. 6: XIV. Zart und singend – Dolce e cantando.ogg” . The western classical musics this combination is very long most almost all the tracks, and these files with huge file names and lot of files having ‘:’ in the name being refused to copied directly. So I needed to truncate or rename the 100 files in a way so that they are identifiable and also truncated to short names.
I decided to keep only the track name and composers names (%n – %a fields), by renaming the files with some batch file renaming process. Continue reading “awk to the rescue”


Bash Script : Finding Digital Root of an Integer

To find a digital roots of an integer is a very common question in high school when doing introductory programming. Digital roots are defined as follows. First an integer is taken if the number of digits are greater than 1, then the sum of its digits are done, if the sum has more than one digits then again the sum of digits are done, and so on until a sum of digit has only 1 digit. This last value of the sum of digits containing a one digit value is defined as the digital root of a number. First we describe in brief what a digital root is then present a shell script.
Continue reading “Bash Script : Finding Digital Root of an Integer”

Install Fedora12 from HDD/USB


My friend told me to install Fedora12 in his laptop with a destroyed DVD drive. What i did first is made a bootable USB and extracted the required files into it from the Fedora DVD ISO image. Then went to the fedoraproject site and read the docs about the requirements and started. With the below process you can install Fedora12, or any distro capable of installing from ISO image, from an HDD, USB or whatever.

Continue reading “Install Fedora12 from HDD/USB”

Installing GRUB Bootloader

GRUB is a very common bootloader on GNU+Linux systems. Many people multi boot their computers with Windows, different flavours of GNU+Linux and other operating systems, and some times GRUB gets destroyed/removed accidentally. In those case there is no other way except reinstalling GRUB. Also when making a bootable USB device GRUB is useful. We will talk about how to install GRUB in a partition with the help of the grub-install script which comes with the GRUB package, and also how to manually install GRUB using grub shell.
Continue reading “Installing GRUB Bootloader”

Choose login manager GDM or KDM in Fedora

Fedora comes with GNOME as the default desktop environment, and GDM as the default login manager. The login manager is the screen you see when logging in. Like GNOME has its login manager, KDE has its own login manager KDM. While logging in you can select which desktop environment you want to use from the sessions menu of the login manager. But there seems to be no ways to switch between these login managers. But you could do this manually by adding a couple of lines to a file. Check this out.

Continue reading “Choose login manager GDM or KDM in Fedora”

Bash Script : Check for palindrome

When learning shell script, a very common script which is given as a task in schools is to write a script to check if a string is a palindrome or not. I am presenting two solutions of this simple problem. A palindrome is a string whose reverse is same as the string itself. Like “madam” is a palindrome but “hello” is not

Continue reading “Bash Script : Check for palindrome”

Latest Myth: Fedora Cannot run Shell Script

A lot of people running around asking for RedHat Linux, suddenly, and most of them at last getting pointed to me and getting disappointed. When asked why RedHat, and why not any one among the hundreds of other distros, I came to know a very important information: “Shell programming cannot be done in fedora”. It was very difficult to understand how this idea spread virally around the 3rd year honours Asutosh College students (a lot of them). The strangest part is even a shell program is run in front of the mass, they refuse to believe that Fedora actually can run shell script. It feels like someone going down to Sachin Tendulkar and telling “Hey man, you know nothing of cricket”.

Whatever it be it is better to get out of this myth and face the cruel reality : “Fedora CAN run shell programs” . Before comments to this post starts raining asking why, let me tell what I know and support my statement.

To run shell scripts you need basically the below three components:

  1. An OS kernel
  2. A shell
  3. The set of commands which will be used in the script

Now, in GNU+Linux systems we have the Linux kernel, The bash shell (some may have others as well), and the standard set of commands are the coreutilities. There are some more packages which contains some commands (programs) which are used.
Each of the above components are very basic and includes in all the GNU+Linux operating systems. Even an OS of size below 10MB can contain the components, which any one with proper knowledge can make for herself. Even before booting the Fedora or any GNU+Linux OS, the initial ramdisk image the initrd runs a long shell script, which configures the system and helps fedora or any GNU+Linux OS to boot.

Conclusion: Fedora can run shell scripts (Sachin can play cricket), provided the programmer knows shell scripting. (provided the bat is not a table tennis bat).

Floating point math operations in bash

When writing scripts in bash, sometimes we need to work with basic math functions. Like the trigonometric functions, square root, cube root, logarithms. Bash does not support floating point operations. This is where the problem is encountered, and we cannot write a math function of our own. There must be a way to do this, and yes. Bash supports redirections so we can feed the floating point computations and the math functions into some other program’s input who understands it. The program which can be used is the bc, which is an arbitrary precision calculator language. bc can do floating point operations, and also can do basic math functions. With bash and bc we can do the above. Continue reading to know how.

Continue reading “Floating point math operations in bash”