Skip to content

Instantly share code, notes, and snippets.

@niko
niko / rename.sh
Last active December 14, 2015 16:08
#!/bin/bash
# Batch renaming files via your sharpest tool - your text editor.
# Given a file pattern as argument renamer.sh opens $EDITOR
# with the selected files. Rename them in the editor, save
# and quit. You will be presented with the rename script
# so you can inspect what will happen when you continue.
# renamer.sh will do the renaming in two steps. First all
# files will be renamed to temporary names with increasing
# IDs. Then the renaming to the final name will be done.
# ala https://www.onli-blogging.de/1463/Sinatra-Code-im-Hintergrund-ausfuehren.html
require 'sinatra/base'
require 'thread/pool'
class Transcode
ThreadPool = Thread.pool(2)
def initialize message
ThreadPool.process do
function greparate() {
PATTERN=$1;
FILENAME=$2;
FILENAME_WITH=`echo $FILENAME | sed "s/\.\([^\.]*\)$/.with_$PATTERN.\1/"`;
FILENAME_WITHOUT=`echo $FILENAME | sed "s/\.\([^\.]*\)$/.without_$PATTERN.\1/"`;
echo "Seprating the content of $FILENAME by $PATTERN into $FILENAME_WITH and $FILENAME_WITHOUT"
grep $PATTERN $FILENAME > $FILENAME_WITH;
grep -v $PATTERN $FILENAME > $FILENAME_WITHOUT;