vim - power of :g

Computing/vim tips 2009.07.28 18:19

팁의 출처 : http://vim.wikia.com/wiki/Power_of_g


회사에서 일을 하다가 trace 파일을 가공해야 할 필요가 생겼다.
다음과 같이 생긴 파일이다 :

[2009-07-28 13:45:36 T-1107208528] LogRecInfoInit :
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528] LogRecInfoInit :
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
00000000: c2 35                                               |.5              |
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
00000000: 74 68 72 33                                         |thr3            |
[2009-07-28 13:45:36 T-1107208528]    blablablablablablablablablablablbalablablablablablabl
00000000: 69 6e 73 65  72 74 20 35  32 30 30 20  20 20 20 20  |insert 5200     |
00000010: 20 20 20 20                                         |                |
[2009-07-28 13:45:36 T-1107208528] blablablablablablablablablablablbalablablablablablabl)
[2009-07-28 13:45:36 T-1107208528] LogRecInfoInit :
[2009-07-28 13:45:36 T-1107208528]  blablablablablablablablablablablbalablablablablablabl
.
.
.

요점은, LogRecInfoInit: 라는 로그 이후에 여러 줄에 걸쳐서 정보가 나오는데,,, 이 상태로는 wc 같은 걸 이용해서 카운트를 한다든지 할 수가 없다. 그래서, 앞의 [ ] 안쪽의 부분을 지우고, LogRecInfoInit: 블록을 한줄로 만들어야 하는데.... ㅡ,.ㅡ)));;

이게 한두개가 아니고, 파일이 무려 십만라인이 넘는 파일이다.

간단한 ex 명령어 두 개로 해결했다 :

:g/2009-07-28/norm 0df]x
:g/LogRecInfoInit :/norm VnkJ

요점 :

:g/Pattern/cmd
cmd :
exe
norm ....

자세한 내용은 :help ex-cmd-index

tags :
Trackback 0 : Comments 5
  1. 하늘섬 2009.07.28 22:33 신고 Modify/Delete Reply

    멋지네요~ vim 마술사 shawn님!

  2. BlogIcon phlow 2009.07.29 10:06 신고 Modify/Delete Reply

    항상 치환하는 것만 대충쓰고.. ( :s )
    나머지 사용법을 지나쳤는데...
    :g (global search & commnad?)를 보니..
    vi가 확 매력적으로 보이네요...ㅎㅎ

    • BlogIcon Orchistro 2009.07.29 10:54 신고 Modify/Delete

      ㅎㅎ 풍부한 이동명령은 텍스트 편집을 더 즐겁(?)게 해 줍니당. 시간나면 놀러 오셈. 자주 쓰는 것 여....러가지가 있으니 알려 드리죠~

  3. BlogIcon Orchistro 2011.07.08 20:04 신고 Modify/Delete Reply

    :v/pattern/ --> pattern에 일치하지 않는 라인들을 표시해 준다.

Write a comment

티스토리 툴바