tags:

views:

48

answers:

2

i have some xml files in linux

a="xx
xx
xx"
b="y
y
y"

How to replace the content and becomes

a="xx\n\xx\nxx"
b="y
y
y"

where attribute b is not replace

i have try this but how to support multi files and replace the attribute "a" only using sed or awk command; (not use xslt)

sed ':a;N;$!ba;s/\n/\\n/g' abc.xml
A: 

gawk

gawk -vRS="\nb=" '/a=/{ gsub("\n","\\n") }
{ if (RT == "") printf "%s", $0
  else print
}' ORS="\nb=" file

output

$ ./shell.sh
a="xx\nxx\nxx"
b="y
y
y"
ghostdog74
thankyou ghostdog^^
brian
A: 

Here's a sed command that should work:

sed -n '/^a/ {:b; $b; N; /^a.*\"$/ {s/\n/\\n/gp;b};bb}; /^a/! p'
Dennis Williamson