0
4

3 回答 3

2

This sed should do the trick on your sample input (but gets overzealous if you have more than one <Connector port="8080" section):

sed '/<Connector port="8080"/,/>/{ s/<Connector.*/xxxx/; t; d  }'

But handling this robustly calls for an XML parser. Example:

#!/usr/bin/env ruby
require 'rexml/document'
include REXML
d = Document.new(File.read(ARGV[0]))
e = d.get_elements('//Connector[@port="8080"]').first
if !e.nil?
    e.parent.insert_after(e, Text.new('xxxx'))
    e.parent.delete(e)
end
File.open(ARGV[0],'w'){|f| f.print(d) }
于 2013-11-14T19:43:02.850 回答
0
sed  '/<Connector port="8080"/,/>/ {
   N
   />/ s/.*/xxxx/
  }' YourFile 

load the section of connector before changing it to xxxx, this allow you to eventually test something on it (but not better than pobrelkey if not)

于 2013-11-14T21:44:21.763 回答
0

Thanks all for the answers , they worked well .Appriciate it: Also i got following from one of my firend which also a answer to this using awk

awk '/<Connector port/ {
print "abc"
getline
do {
 getline
} while (index($0, ">") == 0)
getline
} 
// { print $0}' < 1.txt
于 2013-11-15T14:12:41.210 回答