2012年5月29日火曜日

ch7-read1.sh

input="/etc/hosts"

readfile () {
    while read f[0] f[1] f[2]; do
        # remove line from #                                                                                 
        if [ -z "$(echo ${f[0]} | grep ^#)" ]; then
            echo ${f[0]} ${f[1]}
        fi
        done
}

echo "readfile $input..."
readfile < $input

echo "## pattern 2"

{
    while read f[0] f[1] f[2]; do
        # remove line from #                                                                                 
        if [ -z "$(echo ${f[0]} | grep ^#)" ]; then
            echo ${f[0]} ${f[1]}
        fi
        done
} < $input

0 件のコメント:

コメントを投稿