> Does ksh have an API to edit a file at a specific position pos1, read
> n1 bytes, and write n1 bytes at that position without truncating the
> file? I need this to do edit a file in place without reading and
> writing it completely each time.

Yes, ksh has seek redirection operators.

Here's an ad hoc example (not sure whether the features are
applied proficiently, but it seems to work :-)

f=somefile

cat <<EOT >"$f"
Hello world!
My good friend.
How are you?
EOT

function fun  ## palindrome (just for example)
{
  arg=$1 x=
  (( len=${#arg} ))
  for ((i=0; i<len; i++))
  do  res=${arg:i:1}$res
  done
  printf "%s" "$res"
}

pos1=18
n1=8

read -N "$n1" content 0<>"$f" <#((pos1))
printf "%s" "$(fun "$content")" 1<>"$f" >#((pos1))


Outputs:

Hello world!
My goneirf dod.
How are you?


Hope it's of some use to you.

Janis

                                          
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to