Разрезание текстового файла на несколько частей в Emacs - PullRequest
2 голосов
/ 21 декабря 2010

Я использую редактор GNU Emacs 23.У меня есть этот огромный текстовый файл, содержащий около 10000 строк, которые я хочу разделить на несколько файлов.Использование мыши для выбора необходимого текста для вставки в другой файл является действительно болезненным.Также это также подвержено ошибкам.

Если я хочу разделить текстовый файл по номерам строк, скажем, на 4 файла, где первый файл: строки 1-2500, второй файл: строки 2500-5000, третий файл: строки5000-7500 четвертый файл: строки: 7500-10000

как мне это сделать?По крайней мере, есть ли эффективный способ скопировать большие области файла, просто указав номера строк

Ответы [ 3 ]

3 голосов
/ 21 декабря 2010

Cu твой друг.Попробуйте это:

C-spc (set mark at point)
C-u 2500 <down> (equivalent to pressing the down key 2500 times)
M-w (copy)
3 голосов
/ 21 декабря 2010

Должно работать следующее:

M-<           (go to start of file)
C-space       (set mark at current cursor position)
ESC 2500 down (go down 2500 lines)
C-w           (delete between mark and cursor, and put it in cut buffer)
...           (open new file, using your favourite method)
C-Y           (paste contents of cut buffer)
1 голос
/ 20 августа 2011

Я использую эту команду из misc-cmds.el (http://www.emacswiki.org/emacs/misc-cmds.el).. Вы просто выбираете нужный текст, а затем копируете его в нужный файл - см. Строку документа.


    (defun region-to-file (start end filename arg)
      "With prefix arg, this is `append-to-file'.  Without, it is `write-region'.
    START and END are the region boundaries.
    Prefix ARG non-nil means append region to end of file FILENAME.
    Prefix ARG nil means write region to FILENAME, replacing contents."
      (interactive
       (list (region-beginning) (region-end)
             (read-file-name (concat (if current-prefix-arg "Append" "Write")
                                     " region to file: "))
             current-prefix-arg))
      (let* ((curr-file (buffer-file-name))
             (same-file-p (and curr-file (string= curr-file filename))))
        (cond ((or (not same-file-p)
                   (progn
                     (when (fboundp 'flash-ding) (flash-ding))
                     (yes-or-no-p
                      (format
                       "Do you really want to REPLACE the contents of `%s' by \
    just the REGION? "
                       (file-name-nondirectory curr-file)))))
               (write-region start end filename arg)
               (when same-file-p (revert-buffer t t)))
              (t (message "OK.  Not written.")))))

...