The following bash/GNU awk script should solve the problem:
Code:
#!/bin/bash
WORK="`mktemp -d`" || exit $?
trap "rm -rf '$WORK'" EXIT
while [ $# -gt 0 ]; do
FILE="$1"
TEMP="$WORK/temp"
shift 1
if gawk -v "message=the replacement message" '
{ if (length($0) > 10)
print message
else
print $0
}' "$FILE" > "$TEMP" ; then
if mv -f "$TEMP" "$FILE" ; then
echo "$FILE: Done." >&2
else
echo "$FILE: Cannot replace file." >&2
fi
else
echo "$FILE: Error processing file." >&2
exit 1
fi
rm -f "$TEMP"
done
Or, you could just use
sed instead, replacing any line with eleven or more characters with Message in
file:
Code:
sed -e '/^.\{11\}/ s|^.*$|Message|' -i file