I'd like to add a couple lines of text (copyright) to the top of all text files in a directory. Can I do this in emacs without copy/pasting for each file?
Asked
Active
Viewed 482 times
2 Answers
3
This is copied from Chris Conway's answer to a different question: Using Emacs to recursively find and replace in text files not already open
- M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
- Press t to "toggle mark" for all files found.
- Press Q for "Query-Replace in Files...": you will be prompted for query/substitution regexps.
- Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.
You can use it the same way
0
Yes, with
find . -type f -exec emacs -batch '{}' --eval '(insert-string "foo\nbar\nbaz\n")' -f save-buffer \;
or something to that effect. The emacs bit is
emacs -batch filename --eval '(insert-string "foo\nbar\nbaz\n")' -f save-buffer
replace "foo\nbar\nbaz"
with your message. However, using emacs for this is really a lot of overkill. You could just put your copyright header into a file and use cat header file > tempfile; mv tempfile file
.

Wintermute
- 42,983
- 5
- 77
- 80