我有一个 raw-vobs-config-spec 文件,其中包含这些行,
element /vob/ccm_tpl/repository/open_source/opensso_policy_agt/tomcat-v6/3_0-ER2/... VERSION_04
element /vob/ccm_tpl/repository/open_source/opensso/8_0_build6/... VERSION_01
element /vob/ccm_tpl/repository/open_source/commons_beanutils/1_8_2/... TPLBASE
#element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... TPLBASE
element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... /main/LATEST
element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... /CHECKEDOUT
element /vob/ccm_tpl/repository/open_source/commons_digester/1_8_1/... TPLBASE
element /vob/ccm_tpl/repository/open_source/commons_el/1_0/... TPLBASE
element /vob/ccm_tpl/repository/open_source/commons_jexl/2_0/... TPLBASE
element /vob/ccm_tpl/repository/open_source/commons_scxml/0_9/... TPLBASE
如何删除这些行?
element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... /main/LATEST
element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... /CHECKEDOUT
并取消注释此行
#element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... TPLBASE
我试过了,
sed -i '/patter/d' filename
但它不起作用。
答案 0 :(得分:0)
从文件中删除行的一种快捷方法是将-n
选项与否定模式结合使用:
打印与图案不匹配的行
sed -n '/pattern/!p'
例如:
$ cat foo
foo
bar
baz
$ sed -n '/^b/!p' foo
foo
至于取消评论,只需删除一个领先的#
(在Ed Morton的建议之后):
sed 's/^#//'
上述文件的示例:
$ sed 's/^b//' foo
foo
ar
az