-1

I have a file raw-vobs-config-spec which has these lines,

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

How can I delete the lines?

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

and uncomment this line

#element /vob/ccm_tpl/repository/open_source/commons_collections/3_2_2/... TPLBASE

I tried,

sed -i '/patter/d' filename

but it is not working.

sat
  • 14,589
  • 7
  • 46
  • 65
noob_coder
  • 749
  • 4
  • 15
  • 35

1 Answers1

0

One fast way to delete lines from a file is to use the -n option in conjunction with a negated pattern:

Print lines that do not match the pattern

sed -n '/pattern/!p'

For example:

$ cat foo
foo
bar
baz
$ sed -n '/^b/!p' foo
foo

As for uncommenting, just drop a leading # (after Ed Morton's suggestion):

sed 's/^#//'

Example with the above file:

$ sed 's/^b//' foo
foo
ar
az
  • 1
    @EdMorton Of course! Thank you very much for the pointer. (I am myself still learning, as you can see) –  Feb 16 '16 at 17:59