ShellScript‎ > ‎

Examples

Modify a zone by removing its header of 9 lines then add our header to it and move it from  DNS2 folder to res.

#!/usr/bin/zsh

for f in `ls DNS2/`
do

echo "processing $f"
; primary zone file for $f
; =====================================================
\$TTL 300

@       IN      SOA     ns1.compute.info.       ns2.compute.info. (
                        2010100602      ; serial
                        3600    ; refresh
                        900     ; retry
                        2628000 ; expire
                        600     ; minimum
        )" > res/$f
sed '1,9d' DNS2/$f >> res/$f
sed -i 's/NS/IN      NS/g' res/$f
sed -i 's/ns1.oldplace.net./ns1.compute.info./g' res/$f
sed -i 's/ns2.oldplace.net./ns2.compute.info./g' res/$f

done



Process lines of a text file

#!/bin/sh

processLine()
{
        line="$@"

        # Do as you wish to the each line here
        echo $line
}

FILE=""

if [ "$1" == "" ]; then
        FILE="/dev/stdin"
else
        FILE="$1"
        if [ ! -f $FILE ]; then
                echo "$FILE : does not exists"
                exit 1
        elif [ ! -r $FILE ]; then
                echo "$FILE: can not read"
                exit 2
        fi
fi

exec 3<&0
exec 0<$FILE

while read line
do
        processLine $line
done

exec 0<&3
exit 0


Subpages (1): Usage
Comments