in reply to the manuals fail me

You wouldn't write $index = $index + 1 in bash.

Here's some untested code in Perl:

use autodie; use Fcntl qw[:DEFAULT :seek]; sysopen my $fh, "/tmp/text.index", O_RDWR | O_CREATE, 0666; my $count = <$fh> || 0; seek $fh, 0, SEEK_SET; truncate $fh; print $fh $count + 1; close $fh;
Or use a precanned CPAN solution.