[shell] Repoint an existing symbolic link (symlink) to a different target

Tags

, , ,

$  ln -nsf <TARGET>  <LINK>

Credit: Commandline-fu.

[perl] Access shell environmental variables in your Perl script

Tags

, , , , , , , , , ,

The environmental variables are stored in %ENV hash (“associative array”). Now if you want to access a shell variable, say $HOME, in your Perl script, then you need to refer to it as $ENV{'HOME'}:

#!/usr/bin/perl
$my_home_dir = "$ENV{'HOME'}" ;
$my_shell = "$ENV{'SHELL'}" ;
$my_editor = "$ENV{'EDITOR'}" ;

Don’t forget the curly braces and the single quotes!

Reference: Devdaily blog.

[pdf] Resize a picture in the command line using ImageMagick (convert) and save it as a PDF

Tags

, , , , , , ,

Resize a picture or PDF file by 50% of its original form and save it as a PDF:

$ convert rose.jpg -resize 50% rose.pdf

Well, ‘convert’ may be used to convert between most of the known image formats —- not just JPG and PDF!

N.B. 1. More options may be found at the ImageMagick website. More information on how to specify the geometry may be found here. (If you don’t have ImgeMagick you need to install it first — see the first link for more information on installation!).

2. Here is a list of other useful options/ examples on how to make the best out of ‘convert’.

3. If you’re at playing with PDFs you may also be interested in joining and removing pages from a PDF document using Ghostscript — see a previous post here.

[f77] Concatenate a string with another string or an integer in fortran 77

Tags

, , , , , , ,

Let’s assume that we have defined two strings as

str1 = 'abc'

str2 = 'pqr'

and an  integer

integ = 25

(Make sure str1 and str2, and integ are defined as character strings, and integer, respectively)

1. Concatenate str1 and str2 into str3 (make sure you define str3 first as a character string)

str3 = str1//str2

2. Concatenate str1 and integ into str3 (again make sure str3 is defined as a character string)

step a: convert integer to a string first (make sure str4 is defined as a character string and not initialized, i.e. it’s so far an empty string)

write(str4,'(I5)') integ

step b: concatenate str1 and str4 into str3

str3 = str1//str4

[bash] Substitute dots by hyphens using “tr”

Tags

, , , ,

If you want to replace dots in a string, for example “a.string.with.dots”, by hyphens use the following trick

 

$ echo "a.string.with.dots" | tr  "."  "-"

That’s it!

 

Needless to say, other characters may also be substituted this way.

Design a site like this with WordPress.com
Get started