I need to truncate the lines in a file to 24 characters, to feed to a small dot-matrix printer. How can I do this? I use doom emacs.
Asked
Active
Viewed 108 times
2 Answers
1
From the shell:
cut -c1-24 FILE
In Emacs, interactively:
M-x replace-regexp
RET ^\(.\{24\}\).+
RET \1
RET

phils
- 48,657
- 3
- 76
- 115
0
phils has answered your question, but i wonder if you didn't mean that you wanted to limit the line lengths of a given file so that they'd all print within the constraint of your printer, rather than cutting your lines off.
if that is so, you need to set the fill-column
to a value small enough, and then fill (wrap) your text, which limits your line lengths to the fill-column's value:
use set-fill-column
(C-x f
in vanilla emacs) to set a value for it.
then fill (wrap) your text with e.g. fill-region
or fill-paragraph
. to wrap a whole file you can just select whole buffer with mark-whole-buffer
(C-x h
in vanilla emacs) then run fill-region
.

user27075
- 488
- 3
- 11