LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1709|回复: 3

一个sed的问题,怎样进行多行条件匹配?

[复制链接]
发表于 2005-2-25 11:42:34 | 显示全部楼层 |阅读模式
比如,我有这样的数据:

RD -  REPORT DATE/PAGINATION: Sep 94. 5p.
PY -  PUBLICATION YEAR: 1994
NT -  DESCRIPTIVE NOTE: European congress on molecular spectroscopy (
      22nd), Essen (Germany), 11-16 Sep 1994. Sponsored by Department
      of Energy, Washington, DC.

要把“NT - ”下一行的“\n      "(回车和空格)替换为空,怎么匹配啊,用s/\n      //好像不行啊。
发表于 2005-2-25 12:33:59 | 显示全部楼层
哥们,别忘了,很好用的

[linuxnow@localhost test]$ sed '\cNT -c {n;N;s/\n/ /}' test.txt

RD - REPORT DATE/PAGINATION: Sep 94. 5p.
PY - PUBLICATION YEAR: 1994
NT - DESCRIPTIVE NOTE: European congress on molecular spectroscopy (
22nd), Essen (Germany), 11-16 Sep 1994. Sponsored by Department of Energy, Washington, DC.
RD - REPORT DATE/PAGINATION: Sep 94. 5p.
PY - PUBLICATION YEAR: 1994
NT - DESCRIPTIVE NOTE: European congress on molecular spectroscopy (
22nd), Essen (Germany), 11-16 Sep 1994. Sponsored by Department of Energy, Washington, DC.
RD - REPORT DATE/PAGINATION: Sep 94. 5p.
PY - PUBLICATION YEAR: 1994
NT - DESCRIPTIVE NOTE: European congress on molecular spectroscopy (
22nd), Essen (Germany), 11-16 Sep 1994. Sponsored by Department of Energy, Washington, DC.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-25 16:33:34 | 显示全部楼层
谢了,可是好像不能用,我再找个更复杂的例子,比如像下面的文件,会有连续的几个要去掉回车空格的行,怎么处理呢?

PY -  PUBLICATION YEAR: 1994
NT -  DESCRIPTIVE NOTE: European congress on molecular spectroscopy (
   22nd), Essen (Germany), 11-16 Sep 1994. Sponsored by Department
   of Energy, Washington, DC.
SC -  SUBJECT CATEGORIES: Physics-Solid-state-physics (46D)
CC -  SUBJECT CATEGORY CODES: 46D, 46
AB -  ABSTRACT: Ion-induced damage in GaAs as a function of ion dose
   following 100 keV Si(sup +) implants has been investigated by
   Raman spectroscopy. A new approach for decomposition of Raman
   scattering intensity on to the crystalline and amorphous phase
   components has been used in analysis of Raman spectra. With
   increasing ion dose the following was observed: (a) the widths of
   vibrational bands of a-phase significantly increase, while the
   width of the LO((Gamma)) phonon band of c-phase remains
   unchanged; (b) the longitudinal optical phonon band of c-phase
   completely dissappears, while the transverse optical phonon mode
   evolves in to a new band of a-phase; (c) the wavenumbers of all
   vibrational bands of a- and c-phase shift to lower values by (
   approximately) 10--15 cm(sup (minus)1). A number of mechanisms
   possibly accountable for these shifts were analysed and
   evaluated.

处理后成为:(每个"[A-Z]\{2\} -"作行首)

PY -  PUBLICATION YEAR: 1994
NT -  DESCRIPTIVE NOTE: European congress on molecular spectroscopy (22nd), Essen (Germany), 11-16 Sep 1994. Sponsored by Department of Energy, Washington, DC.
SC -  SUBJECT CATEGORIES: Physics-Solid-state-physics (46D)
CC -  SUBJECT CATEGORY CODES: 46D, 46
AB -  ABSTRACT: Ion-induced damage in GaAs as a function of ion dose following 100 keV Si(sup +) implants has been investigated by Raman spectroscopy. A new approach for decomposition of Raman scattering intensity on to the crystalline and amorphous phase components has been used in analysis of Raman spectra. With increasing ion dose the following was observed: (a) the widths of vibrational bands of a-phase significantly increase, while the width of the LO((Gamma)) phonon band of c-phase remains unchanged; (b) the longitudinal optical phonon band of c-phase completely dissappears, while the transverse optical phonon mode evolves in to a new band of a-phase; (c) the wavenumbers of all vibrational bands of a- and c-phase shift to lower values by (approximately) 10--15 cm(sup (minus)1). A number of mechanisms possibly accountable for these shifts were analysed and evaluated.
回复 支持 反对

使用道具 举报

发表于 2005-2-25 17:24:12 | 显示全部楼层
这个。。。有些难 ;)
提示一下,用sed分支处理
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表