thefekete.net

$> :(){ :|:& };:

Bash script / function to append file names

In my previous post about appending file names, I made a one-off solution.

Here’s a bash function that you can throw in your .bashrc and use more easily:

#!/bin/bash

# Put this in your ~/.bashrc and use it like a script...
append_filename() {
    USAGE="append: Puts text between filename and extension"
    USAGE="$USAGE\nUsage: $0 APPENDAGE file1 file2 file3 ..."

    if [ "$#" == "0" ]; then
        echo -e "$USAGE"
        return 1  # exit kills shell this is called from
    fi

    # get appended string
    APPENDAGE=$1
    shift

    while (( "$#" )); do
        if [ -f "$1" ]; then  # don't rename directories
            mv "$1" "${1%.*}$APPENDAGE.${1##*.}"
        fi
        shift  # grab the next file in list
    done
}

Appending filenames, not extensions

I had a group of files that I needed to append a suffix to, but leave the extension intact. Basically, I needed to split the filename and extension, then put them back together with some filling in the middle…

This answer @ stack overflow shows how to split them, and then it’s pretty easy to put them back together:

#!/bin/bash
FILLER='-1'  # Whatever you want to append to the filename
for i in *
do
    mv $i "${i%.*}$FILLER.${i##*.}"
done

Two Simple Guitar Amps

Was messing around the last couple of days with my guitar, and got a little too close to the electronics bench…

I ended up with the following small amp circuits (I say small, but these things are louder than shit through a 1×12 cabinet):

Single LM386 1/2W Amp

Dual LM386 1W Amp

Here’s a pic of the bridged circuit on the breadboard:
Breadboarded Bridged LM386 Amp

Anyways, waiting for some JFETs in the mail so I can wire up some proper preamps.

These closely follow the the example circuits in the datasheet, but many thanks to runoffgroove.com for the great examples – particularly the little gem designs.

Splitting large files for a FAT32 removable drive or flash drive

If you got a file or group of files to put on a removable drive with a FAT32 file system – and any of them are over 4GB – then you need a way to make it smaller for transport. The easiest way is with split, cat and tar.

Read the rest of this entry »