Friday, March 31, 2017

Bash: Scripting - rewrite trimeline


#!/bin/bash
#
#
FILE=/homeb/d54712/sandbox/scripts/data.d/lorem.txt
#
exec 3< $FILE
function trimline ()
{
        #IFS='\n'
        MAXLEN=$(($LINELEN - 3))
        if [ "${#1}" -le $LINELEN ]
        then
                echo "$1"
        else
        echo " ${1:0:${MAXLEN}} \\"
        fi
}
exec <&0
LINELEN=${1:-80}
exec <&3
while read line
do
        #echo "$line"
        trimline "$line"
done

No comments:

Post a Comment