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

09 Jun 2007 Text manipulation using sed

Replace string1 with string2

sed 's/string1/string2/g'

Modify anystring1 to anystring2

sed 's/\(.*\)1/\12/g'

Remove comments and blank lines

sed '/ *#/d; /^ *$/d'

Concatenate lines with trailing \

sed ':a; /\\$/N; s/\\\n//; ta'

Remove trailing spaces from lines

sed 's/[ \t]*$//'

Escape shell metacharacters active within double quotes

sed 's/\([\\`\\"$\\\\]\)/\\\1/g'

Print 1000th line

sed -n '1000p;1000q'

Print lines 10 to 20

sed -n '10,20p;20q'

Extract title from HTML web page

\(.*\)< \/title>.*/\1/ip;T;q'<br />sed -n 's/.*

Tags:

Posted by

07 Jun 2007 Replace word in files

Example: replace Strict with Transitional in your PHP-files

sed -i -e 's/Strict/Transitional/' *.php

Warning!
Edit files in place

Tags:

Posted by

28 May 2007 A EXIF dater script

The script below will take a filename eg: DSCN0001.JPG, extract the “Image Created” metadata and rename the original file to something like 2006-03-23_DSCN00001.JPG and it will do it automatically for you.

#! /bin/shfunction usage() {if [ $# -ne 1 ]; then    echo "ExifDater - version 0.1 - March 23 2006"    echo "El-Lotso ”    echo “This  is  free  software;  see the source for copying conditions.”    echo “There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR”    echo “A PARTICULAR PURPOSE.”    echo    echo “ExifDater utilises the exiftags( http://johnst.org/sw/exiftags/)”    echo “program to sequentially extract the image creation date from”    echo “JPEG EXIF headers.”    echo    echo “Usage:”    echo “$0 /path/to/jpg/directory”    exit 0fi}function exiftimexist(){which exiftime > /dev/null 2>&1if [ $? -ne 0 ]; then    echo    echo “Unable to locate exiftime binary”    echo “Please make sure it is installed and is in your path.”    echo    exit 0fi}function gotodir(){cd $1 > /dev/null 2>&1if [ $? -ne 0 ]; then    echo    echo “Directory does not exists”    echo “Please try again.”    echo    exit 0fi}function jpgexist(){find . -iname “*.jpg” -type f >/dev/null 2>&1if [ $? -ne 0 ]; then    echo    echo “There are no JPEG pictures in this directory”    echo “Please try again.”    echo    exit 0fi}function myexifdater(){for i in *.jpgdo    create_date=`exiftime “$i” 2>&1 | grep -i image created | cut -d” ” -f3 | sed -e ’s/:/-/g’`    if [ “$create_date” == “” ]; then        echo -e “SKIPPING IMAGE $i \t\t\t [NO EXIF DATA FOUND]”        continue    fi    echo -n Processing Image $i Created on $create_date    do_rename=$( echo $i | sed -e ’s/(.*)/mv “&” “‘$create_date’_1″/g’|sh)    echo -e \t[DONE]done}usage $1exiftimexistgotodir $1jpgexistmyexifdater

Usage: ExifDater /your/picture/pathDownload the ExifDater script.There is also a Windows version of a program that’s called ExifDater for those who need that :)Source: http://lotso.livejournal.com/2006/03/23/

Tags: , , , ,

Posted by

25 May 2007 Strip comments from config files

This is at short script to strip/remove comments from config files

#!/bin/bash
# Code to cat a config file removing all comments and blank lines.

grep -vh '^[[:space:]]*#' "$@" | grep -v '^$'

Usage: ./confcat.sh /etc/make.conf

Alternativ is to use sed

cat filename | sed -e 's/#.*//;/^\s*$/d' "$@"

This also strips comments at the end of a line, though it looks a little bit ugly

Tags: , ,

Posted by

20 May 2007 List only directories

ls -F $1 | grep \/ | sed -e 's/\/$//g'

Tags: ,

Posted by