Advertisement
haiv

Write to the middle of a file

Nov 6th, 2012
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 0.42 KB | None | 0 0
  1. #!/usr/bin/env tclsh
  2.  
  3. # Open the file, with truncation
  4. set f [open foo w]
  5. puts $f "one"
  6. puts $f "two"
  7. close $f
  8.  
  9. # Open again, with a+ ==> read/write/append
  10. set f [open foo a+]
  11. puts $f "three" ;# This goes to the end of the file
  12. seek $f 4       ;# Seek to the beginning of the word "two"
  13. puts $f "2.0"   ;# Overwrite the word "two"
  14. close $f
  15.  
  16. # Open and verify the contents
  17. set f [open foo r]
  18. puts [read $f]
  19. close $f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement