You are currently browsing articles tagged bash.

Because I’m fed of searching for this kind of useful command :

$ for F in *; do E=${F:(-4)}; B=${F/$E/}; mv $F 'Wonderful.Serial.FileName.S03E'$B.'VOSTFR.HDTV.XViD.GKS'$E; done

Explanations :
E = ${F:(-4)} extracts the file extension.

B = ${F/$E/} returns the original filename without extension.

These two variables are then used to build the new filename 🙂


Another one, using sed and regular expressions :

$ for A in *.avi; do mv "$A" `echo $A | sed -r 's/^Name To Remove <ins>([0-9]</ins>(-[0-9]+)?)\.avi$/\1.avi/'`; done

Were we build a simple “mv” command with the original filename ($A) and a new filename by catching the output of echo $A | sed enclosing it with backquotes (`).

sed -r allows to use extended regular expressions.

s/you/me/ is the sed command to Subsitute you by me.

s/^Name To Remove ([0-9](-[0-9]+)?)\.avi$/\1.avi/

We match filenames like :

  • Name To Remove 123.avi (as many spaces as you want between the textual part of the name and the file number)
  • Name To Remove 123-456.avi

    We catch the subexpression between parenthesis (123 or 123-456 in this poor example) and we use it to build the new filename (thanks to ”\1” in the third part of the sed command.)

Tags: , , ,

This is my first released backup script for Firebird RDBMS. It automagically search for all Firebird databases from a central directory, uses gfix to validate them, then backup + gzip them to a central backup directory keeping only 5 last successful backups.

It may be used as a cron script to automate Firebird databases backup. Read the rest of this entry »

Tags: , , ,