msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

09 Feb 2007 Copy several files to a new filename

for f in *.dist; do cp $f `basename $f .dist`; done

Tags: ,

Posted by

02 Feb 2007 Resize of images in a folder with imagemagick

#!/bin/bash
# Hans-Henry Jakobsen
# Script som bl.a resizer bilder og legger de i rett mappe
# NB! ikke bruk originalfil da dette script sletter fila

# Sjekker at mapper eksisterer
if [ ! -d 320 ]
        then
        mkdir 320
fi
if [ ! -d 480 ]
        then
        mkdir 480
fi

for file in  $(ls|grep JPG)
do
        base320=`basename $file .JPG`_Resized_320.png
        base480=`basename $file .JPG`_Resized_480.png

        convert $file -resize 320 $base320
        convert $file -resize 480 $base480

        #320px
        convert $base320 -background black \
        -font Verdana -pointsize 10 -fill black \
        -gravity center -set caption "Copyright \© 2007 Pario.no"  +polaroid \
        320/$base320;

        #480px
        convert $base320 -background black \
        -font Verdana -pointsize 10 -fill black \
        -gravity center -set caption "Copyright \© 2007 Pario.no"  +polaroid \
        480/$base480;

        # Sletter temp filer
        rm $base320
        rm $base480
        # Ikke bruk originalfil da den blir slettet!
        rm ${file}
done

# Ordner rettigheter
chmod g+rw 320/*
chmod g+rw 480/*
chgrp knausen 320 -R
chgrp knausen 480 -R

Tags: , , , , ,

Posted by

01 Feb 2007 Reverse text content in file

#!/bin/bash
# Bash shell script to reverse text file contain i.e. concatenate files and
# print on the standard output in reverse. This script also demonstrate how
# to use arrays under bash shell script.
FILE="$1"
if [ $# -eq 0 ]; then
echo "$(basename $0) - file-name"
exit 1
fi

textArray[0]="" # hold text
c=0 # counter
# read whole file in loop
while read line
do
textArray[c]=$line # store line
c=$(expr $c + 1) # increase counter by 1
done < $FILE
# get length of array
len=$(expr $c - 1 )

# use for loop to reverse the array
for (( i=$len; i>=0; i-- ));
do
echo ${textArray[$i]}
done

Tags: ,

Posted by

01 Feb 2007 Rename files from upper- to lowercase or vice versa

#!/bin/bash
#
# Shell script to rename given file names to from uppercase to
# lowercase OR lowercase to uppercase
FILES="$1"
ME="$(basename $0)"
# function to display message and exit with given exit code
function die(){
echo -e "$1"
exit $2
}
# exit if no command line argument given
[ "$FILES" == "" ] && die "Syntax: $ME {file-name}\nExamples:\n $ME xyz\n $ME \"*.jpg\"" 1 || :
# scan for all input file
for i in $FILES
do
# see if upper to lower OR lower to upper by command name
[ "$ME" == "2upper" ] && N="$(echo "$i" | tr [a-z] [A-Z])" ||  N="$(echo "$i" | tr [A-Z] [a-z])"
# if source and dest file not the same then rename it
[ "$i" != "$N" ] &&  mv "$i" "$N" || :
done

Tags: ,

Posted by