Sunday, May 29, 2011

Shell script to translate uppercase text to lowercase

Bookmark and Share

While shell scripting on UNIX/LINUX/SOLARIS/AIX et cetera, it is often a requirement to translate uppercase characters to lowercase characters.

It can be a user input or contents of file that one might be processing using shell scripting.

Below one liner uses ‘tr’ CLI to translate uppercase characters to lowercase characters.

# strName=”TECHSUTRAM IN LOWERCASE"
# echo $strName| tr ‘[A-Z]’ ‘[a-z]’
techsutram in lowercase

Simple, isn’t it? However, there is a catch. The ‘tr’ CLI used for translation might not work on all UNIX flavors to convert all uppercase characters to lowercase.

The trick is to use slightly lengthy form of ‘tr’ to make translation almost portable to other UNIX flavors. So above code can be rewritten as,

# strName=”TECHSUTRAM IN LOWERCASE"
# echo $strName| tr ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’ ‘abcdefghijklmnopqrstuvwxyz’
techsutram in lowercase

Same mechanism works for translating lowercase characters to uppercase characters as below.

# strName=”techsutram in uppercase"
# echo $strName| tr  ‘abcdefghijklmnopqrstuvwxyz’ ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’
TECHSUTRAM IN UPPERCASE
 

That’s it. This trick has worked for me.
Do you know any other common method that can be used to translate uppercase characters to lowercase characters? If YES then let everyone know in comments below.

 

You may also be interested in,
+ Converting .wav to .mp3 file format in Linux
+ MD5SUM for all files in directory
+ FTP file upload using shell script on LINUX/UNIX


Wednesday, May 11, 2011

Converting .wav to .mp3 file format in Linux

Bookmark and Share

I just had a requirement to convert a CD with .wav files to .mp3 format. The first thing which I did was to boot into OpenSuse 11.3 box and  launch lame.

e.g. to convert Test.wav file to Test.mp3, we can use following syntax,

# lame –h –b 192 Test.wav Test.mp3

We can use above CLI to process set of files using following one liner assuming all .wav files are in current directory,

# for FILE in `ls *.wav`;do `which lame` –h –b 192 $FILE ${FILE//\.wav}.mp3;done

That's it!

You may also be interested in,
+ Shell script to translate uppercase text to lowercase
+ MD5SUM for all files in directory
+ FTP file upload using shell script on LINUX/UNIX


Sunday, May 8, 2011

CPAN update all PERL modules

Bookmark and Share

Below is one liner that can be used to update all PERL modules,

#perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'

However, some modules eventually requires unstable version of PERL. Its just a matter of choice to go with unstable version of PERL.

I tried this CLI on OpenSuSe 11.3 and it worked well for me.


 




Technology