Reputation: 2165
I'm creating a function that adds a column to a flat file. So far I have:
(defun ff-from-vector (vec dir file)
(with-open-file (ff-vec-str (make-pathname :name file
:directory dir)
:direction :output
:if-exists :overwrite)
(dotimes (i (length vec))
(format ff-vec-str "~A~%" (svref vec i)))))
(defun vec-from-1col-ff (dir file)
(let ((col (make-array `(,(ff-rows dir file)))))
(with-open-file (ff-col-str (make-pathname :name file
:directory dir)
:direction :input)
(do ((line (read-line ff-col-str nil 'eof)
(read-line ff-col-str nil 'eof))
(i 0 (incf i)))
((eql line 'eof))
(setf (aref col i) (read-from-string line))))
col))
(defun add-col-to-ff (col-dir col-file ff-dir ff-file)
(ff-from-vector (vec-from-1col-ff col-dir col-file)
ff-dir
ff-file))
However, when I read from the file:
2
2
2
2
And try to overwrite the file:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
I get:
2
2
2
2
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Essentially my question is: what function or code moves the formatting to the end of the line in the output file? So that I can get:
1 1 1 1 2
1 1 1 1 2
1 1 1 1 2
1 1 1 1 2
Upvotes: 0
Views: 71
Reputation: 139321
You can't simply add more output to individual lines in a file without overwriting some data.
Create a new file and place the output there, taking the data from two input files.
Upvotes: 1