Scripting

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’ […]

Read More
Linux

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 ” […]

Read More
Scripting

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 […]

Read More