읽기에 도움이 되는 강조 표시를 사용하여 Emacs에서 구분 기호로 구분된 값 파일을 보는 방법은 무엇입니까?

읽기에 도움이 되는 강조 표시를 사용하여 Emacs에서 구분 기호로 구분된 값 파일을 보는 방법은 무엇입니까?

읽기에 도움이 되는 강조 표시를 사용하여 Emacs에서 구분 기호로 구분된 값 파일을 보는 방법은 무엇입니까?

이상적으로는 구분 기호 문자/문자열을 사용자 정의할 수 있어야 합니다.

Emacs가 할 수 없다면 Linux에서 이 작업을 위해 사용할 수 있는 다른 도구가 있습니까?

답변1

@Ammar의 솔루션과 관련하여 org-table-convert-region구분 기호에 대한 정규식을 사용하도록 명령을 "수정"하는 것은 어렵지 않습니다. 이 경우에는 %%. 한 줄을 추가했습니다.

(defun org-table-convert-region (beg0 end0 &optional separator)
  "Convert region to a table.
The region goes from BEG0 to END0, but these borders will be moved
slightly, to make sure a beginning of line in the first line is included.

SEPARATOR specifies the field separator in the lines.  It can have the
following values:

'(4)     Use the comma as a field separator
'(16)    Use a TAB as field separator
integer  When a number, use that many spaces as field separator
nil      When nil, the command tries to be smart and figure out the
         separator in the following way:
         - when each line contains a TAB, assume TAB-separated material
         - when each line contains a comma, assume CSV material
         - else, assume one or more SPACE characters as separator."
  (interactive "rP")
  (let* ((beg (min beg0 end0))
         (end (max beg0 end0))
         re)
    (goto-char beg)
    (beginning-of-line 1)
    (setq beg (move-marker (make-marker) (point)))
    (goto-char end)
    (if (bolp) (backward-char 1) (end-of-line 1))
    (setq end (move-marker (make-marker) (point)))
    ;; Get the right field separator
    (unless separator
      (goto-char beg)
      (setq separator
            (cond
             ((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
             ((not (re-search-forward "^[^\n,]+$" end t)) '(4))
             (t 1))))
    (goto-char beg)
    (if (equal separator '(4))
        (while (< (point) end)
          ;; parse the csv stuff
          (cond
           ((looking-at "^") (insert "| "))
           ((looking-at "[ \t]*$") (replace-match " |") (beginning-of-line 2))
           ((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
            (replace-match "\\1")
            (if (looking-at "\"") (insert "\"")))
           ((looking-at "[^,\n]+") (goto-char (match-end 0)))
           ((looking-at "[ \t]*,") (replace-match " | "))
           (t (beginning-of-line 2))))
      (setq re (cond
                ((stringp separator) separator) ;; <-- I added this line
                ((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
                ((equal separator '(16)) "^\\|\t")
                ((integerp separator)
                 (if (< separator 1)
                     (error "Number of spaces in separator must be >= 1")
                   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
                (t (error "This should not happen"))))
      (while (re-search-forward re end t)
        (replace-match "| " t t)))
    (goto-char beg)
    (org-table-align)))

불행하게도 그것은 나에게 매우 실망스러운 일이 아니며 |따옴표를 전혀 처리하지 않습니다. 구분 기호가 셀에 나타나지 않는다고 가정하면 |다른 것으로 대체할 함수(예: \vert{}LaTeX로 내보내려는 경우 또는 유니코드 문자인 ⏐ VERTICAL LINE EXTENSION)를 작성하고 다음을 실행하는 것이 어렵지 않습니다. 의 수정된 버전입니다 org-table-convert-region. 원한다면 "%%and %%"로 교체할 수도 있습니다 . %%물론 나는 %%당신이 원하는 구분 기호(함수에 대한 인수가 될 수 있음)에 대한 대체 문자로 사용했습니다.

그것은 모두 해당 파일을 얼마나 자주 볼 것인지, 그리고 해당 파일에 얼마나 많은 작업을 쏟고 싶은지 알기 위해 필요한 기능에 따라 달라집니다. :-)

답변2

Emacs에서는 highlight-phrase( M-s h p) 또는 highlight-regexp( M-s h r)를 사용하여 일부 텍스트를 강조 표시할 수 있습니다.

답변3

구분 기호를 |로 변경할 수 있습니다. (예: 로 sed, 그러나 먼저 모든 |를 다른 것으로 대체), 하나 추가 | 모든 줄 시작과 줄 끝으로 파일을 emacs로 엽니다 org-mode.

csv-mode및 을 사용할 수도 있습니다 csv-align-fields.

답변4

조직 모드가 있는 경우 CSV 파일을 열고 주요 모드를 조직 모드로 설정하고 전체 버퍼를 표시한 다음 을 클릭하여 C-|CSV 파일을 조직 모드 테이블로 변환합니다.

Emacs의 계산과 결합하면 조직 모드 테이블에 대해 무엇이든 할 수 있습니다. 이는 스프레드시트 응용 프로그램보다 더 강력합니다.여기참고용.

Linux의 경우 CSV 파일을 처리하는 데 사용할 수 있는 도구가 끝없이 많지만 스위스 칼은 awk이어야 합니다. 가능하다면 awk를 배우십시오. 그러면 인생이 더 쉬워질 것입니다.

관련 정보