Rojakcoder
Of Linux, Programming, and Singaporean Ramblings

Stripping Carriage Returns From Text Files

Tue, Aug 19, 2014

One of the problems with working on Linux and Windows OSes has to do with manipulating text files. Lines are separated by a carriage return and a line break character in text files on Windows, whereas on Linux, they separation is done through a single line break character.

When text files from Windows are opened in Linux, you often see ^M appearing at the end of lines like this:

Line 1^M
Line 2^M

The easiest way to remove the carriage return characters (represented by ^M) is to use the dos2unix command. This lightweight program can be easily obtained on Debian-based systems with the command:

sudo apt-get install dos2unix

Other than using the dos2unix command, the fastest way to remove the carriage return characters is the following command:

cat file1.txt | tr -d '\r' > file2.txt

Resizing Multiple Images in Linux

Sun, Nov 29, 2009

During the lifetime of using the computer, I believe everyone will inevitably face the scenario where you will want resize multiple images to a certain size.

In Linux, you can do it will such ease that makes you wonder what you use Windows for.

This effect can be easily done using the command line. Naysayers will probably disclaim the effectiveness of this tip but it really is easy for those who know Linux. All you have to do is to go into the directory where the images are stored and run the following command:

for k in $(ls *.jpg); do convert $k -resize 1024x768 -quality 100 re_$k; done

Read more
Tags: linux bash

Restoring GRUB for Linux

Wed, Jun 3, 2009

Frequent Linux users who dual boot their machines with Linux and Windows will inevitably find their GRUB boot loader corrupted at some point in time. This post will help you restore your GRUB boot loader.

Read more
Tags: linux

Converting PS files to PDF

Fri, Aug 29, 2008

In openSUSE 10.3, there is no readily available solution (that I know of) that lets a user print to PDF. The closest thing there is to that is a PostScript (PS) file. Fortunately there is a easy way to convert PS files to PDF. There is a command called ps2pdf which does exactly that. Its usage is very straightforward as well:

ps2pdf document.ps document.pdf

How much simpler can that get?

Tags: linux

Installing Fonts in Linux

Thu, Aug 28, 2008

Installing fonts has been somewhat of a neglect in Linux. Although I haven’t checked, it seems that recent distributions of SUSE Linux has made it GUI-friendly.

Nevertheless, being a console guy, I believe it’s better to know a more reliable way to make things work that is more ‘portable’ (i.e. work in other distributions as well).

So for fonts, the most straightforward way I know is to copy the font into your personal directory’s hidden font folder e.g. /home/coder/.fonts

After having done that, the next step is to then make the font available to your applications. This can be done with the command:

fc-cache -fv

That’s all there is to it!

Tags: linux

Making the USB Thumbdrive Bootable

Thu, Aug 7, 2008
In my previous post, I mentioned that I sometimes have trouble using the mksusebootdisk script make the thumb drive bootable. In a recent endeavour to install openSUSE 10.3 onto the Eee PC again, I encountered the same problem. This time though, I was in a rush for time and simply refused to do the whole process from formatting the file system (till this date I still have not figured out what is the cause of the problem).
Read more
Tags: linux
Page 1 of 2