怎样提取 感兴趣的行,并写入 另一个文件中?

Vim、Emacs配置和使用
回复
arjon
帖子: 1
注册时间: 2009-08-26 15:22

怎样提取 感兴趣的行,并写入 另一个文件中?

#1

帖子 arjon » 2009-08-26 15:28

如题!
请问:
vim 打开的buffer中有很多行, 我想把 其中的 含有 pattern 字符串的行 提取到 另一个文件 file中,
我用
:g/pattern/write file
发现不行。


请指点一二!Thks1
头像
懒蜗牛Gentoo
论坛版主
帖子: 7353
注册时间: 2007-03-02 17:36
系统: Linux Mint

Re: 怎样提取 感兴趣的行,并写入 另一个文件中?

#2

帖子 懒蜗牛Gentoo » 2009-08-26 15:33

非要用vim么?

cat filename |grep pattern >> file2
虽然世上没有完美的东西,但这并不影响我们追求完美,因为只有偏执狂才TMD能成功。
10.04新手入门——笨兔兔讲述自己的故事
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 怎样提取 感兴趣的行,并写入 另一个文件中?

#3

帖子 eexpress » 2009-08-26 15:39

学正则吧。
● 鸣学
头像
GiL
帖子: 690
注册时间: 2006-11-15 14:30
来自: 海滨小城

Re: 怎样提取 感兴趣的行,并写入 另一个文件中?

#4

帖子 GiL » 2009-09-03 2:03

You can also "write" a specific portion of a file to a new filename. By prefixing the :up
command with a line range only the specified lines are written to the named file. For example,
:20,30up 20-30.txt saves lines twenty to thirty of the current buffer to a file named
20-30.txt. Alternatively, select a portion of a file visually then execute :up filename
and the text you selected will be written to a file named filename.
这个?
回复