Michele Marcionelli - Head of IT at D-MATH

Bash Tips and Tricks

This page it just an unsorted collection of "Tips and Tricks" that I use sometime... when my memory fails and I can't remember such things ;-)

vim

Justify

:%!par -j

Convert all HTML-tags to lowercase:

:%s/<[^>]*>/\L&/g

Remove ^M from end of lines (to make ^M use crtl+v & crtl+m):

:%s/^M/\n/g

Diff of saved file and current editing:

:w !diff % -

The «in-file» configuration. To override the default vim configuration one can add at the end(!) of his/her file (depending on the type) following code:

## vim:set ts=20:
// vim:set ts=20:
<!-- vim:set ts=20: -->

sed

Prints lines 3 to 8:

sed -n '3,8p' file

Prints lines 3 to the end:

sed -n '3,$p' file

Print from matching line with "regex1" to matching line with "regex2":

sed -n '/rexex1/,/regex2/p' file

Omit lines 3 to 8:

sed '3,8d' file (omit lines 3 to 8)

date

Seconds since the unix epoch:

date +%s
==>
1262783786

A kind of inverse function:

date -d=@1262783786
==>
Wed Jan 6 14:16:26 CET 2010