Replace the text in sed -
i have
<funcprototype> <funcdef>void <function>foo</function></funcdef> <paramdef>int <parameter>target</parameter></paramdef> <paramdef>char <parameter>name</parameter></paramdef> </funcprototype> <funcprototype> <funcdef>void <function>foo2</function></funcdef> <paramdef>int <parameter>target2</parameter></paramdef> <paramdef>char <parameter>name2</parameter></paramdef> </funcprototype>
i need : void foo( int tagret char name) void foo2( int tagre2 char name2)
using sed can
void foo( int target char name ) void foo2( int target2 char name2 )
i using command
awk "/\<funcprototype\>/,/\<\/funcprototype\>/ { print }" foo.xml | sed 's/^[ ^t]*//;s/[ ^]*$//'|sed -e '/^$/d'|sed 's/ //g'| sed 's/<funcprototype>//;s/<funcdef>//;s/<function>/ /;s/<\/function><\/funcdef>/(/;s/<paramdef>//;s/<parameter>/ /;s/<\/parameter><\/paramdef>//;s/<\/funcprototype>/)/;'
how can want?
processing file formats xml in sed hack, "correct" solution highly depends on inputs want except. following sed script @ least works fine on example data provided:
:loop /<\/funcprototype>/ ! { n; b loop; } s/\n/ /g; s/<\/\?\(funcdef\|parameter\|function\|funcprototype\)>//g; s/<paramdef>/(/g; s/<\/paramdef>/)/g; s/) *(/, /g; s/ */ /g; s/^ //; s/ $//; s/ (/(/;
the interesting bit :loop
part in first 2 lines: :loop
line defines label , 2nd line appends next line input buffer , jumps label until buffer contains closing </funcprototype>
tag. after 2 commands whole multi-line <funcprototype> .. </funcprototype>
block in buffer (with \n
characters separating lines). newline characters replaced blanks using command s/\n/ /g
in 3rd line.
Comments
Post a Comment