Replace new lines in

I have xml files in linux

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

How to replace content and becomes

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

where the attribute b does not replace

I tried this, but how to maintain multiple files and replace the “a” attribute only with the sed or awk command; (do not use xslt)

 sed ':a;N;$!ba;s/\n/\\n/g' abc.xml 
0
source share
2 answers

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" 
0
source

Here is the sed command that should work:

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

All Articles