Archive for January, 2010

VIM Control Characters – search and replace

Monday, January 25th, 2010

Control characters require an escape sequence prior to using in a search and replace operation in VIM. In Linux, the escape character is Ctl-v. Windows requires a Ctl-q.

Remove all ^M characters from a file on Linux:

%s/^V^M//g

Remove all ESCAPES (\27, ^[) from a file on Windows:

%s/^q^[//g

Bash Tip! Renaming files using Bash string operations

Wednesday, January 6th, 2010

To rename all html files in a particular directory to shtml files, use the following loop:

for file in *.html
do
  mv ${file} ${file%%.html}.shtml
done

This uses the ${variable%%match} format which strips the longest match from the end of the variable.