$ ln -nsf <TARGET> <LINK>
Credit: Commandline-fu.
29 Monday Aug 2011
$ ln -nsf <TARGET> <LINK>
Credit: Commandline-fu.
13 Sunday Mar 2011
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.
10 Thursday Mar 2011
Tags
In connection to my previous post on SVN intro, here’s a neat trick to list SVN commits by a user for a given date range:
$ for i in `svn log -r{2011-02-01}:HEAD | awk '$3 == "user" {print $1}'`; do svn log -v -$i;done
Note: It does not work in t/csh shells since you need a different looping structure (see a recent post on t/csh loops).
Reference: Command-Line-Fu.
20 Friday Nov 2009
To know the return value of a command, in BASH run
$ echo $?
and in CSH/ TCSH run
$ echo $status
which will give you the return value (0 or 1) of the last command (the one issued just before the echo).
In both the shells, if the above spits out 0 (zero), it means the previous command was successfully completed, otherwise it’ll give rise to 1 (unsuccessful!) — quite contrary to our concept of 0 being false and 1 being true, eh!
Credit: Oracle Spin.
24 Saturday Oct 2009
The problem: I have two files, file-1 and file-2, each of which has two columns; and I want to add the second column of the second file as the third column in the first file.
Let’s say the following is the content of file-1:
AÂ Â 1
BÂ Â 2
C Â 3
and that of file-2:
D Â 4
EÂ Â 5
FÂ Â 6
and I want to have something like this in file-3
A Â 1Â Â 4
B Â 2Â Â 5
C Â 3Â Â 6
Of course, the actual data are not as simple as the above!
Solution:
$ awk '{str1=$1; str2=$2; getline < "file-2"; print str1" \t "str2" \t "$2 > "file-3"}' file-1
I inserted the tab characters (\t) just to make file-3 look nice (scientists don’t care about white spaces, do they?)!
Reference: here.
UPDATE: As reader ‘boul oumag’ pointed out, an alternative to this is to use the command line utility ‘paste’. Â Â It concatenates each pair of lines — the corresponding ones from each file — and prints it out in the standard output. There is no option to choose which columns to merge. However, you can always redirect the output to a file, open it with vim and reorder/delete columns using vim’s visual block mode (use control+V).