How to silently (in background) create a new line at the end of a specific file, say /path/to/file.txt
(which is not necessarily a visiting file and is not necessarily already open in emacs) and insert some string (say xyz
) in that new line and then to save the file after?
Add a comment
|
You can use the append-to-file
and write-region
functions, for example,
~ $ echo hello > file.txt
~ $ emacs --batch --eval '(append-to-file "xyz\n" nil "file.txt")'
~ $ cat file.txt
hello
xyz
~ $
See also (info "(elisp) Writing to Files")
.
-
Thanks, hence the answer is (append-to-file "xyz\n" nil "/path/to/file.txt"). – Name Feb 2 '18 at 13:12