0

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
RamaPrakasha
  • 113
  • 4

2 Answers2

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