@InnocentSpirit: Попробуйте:
awk '{sub(/" \/>\n<\/Module/,"",$2);gsub(/^\n| +<Name>|<\/Name>|<Property Name="| \/>|>$/,"",$2);gsub(/" Value="/,"; ",$2);gsub(/" \/>/,",",$2);print $2} ' RS= FS="<Module>" Input_file
Добавление неодномерной формы вкладыша слишком в то же самое, вы можете запустить его в режиме сценария тоже.
awk '{
sub(/" \/>\n<\/Module/,"",$2);
gsub(/^\n| +<Name>|<\/Name>|<Property Name="| \/>|>$/,"",$2);
gsub(/" Value="/,"; ",$2);
gsub(/" \/>/,",",$2);
print $2
}
' RS= FS="<Module>" Input_file
Выход будет следующим.
VEG
Carrot; Orange,
Cabbage; Green,
Tomato; Red
FRUITS
Apple; Red,
Mango; Yellow
EDIT: Объяснение выше кода тоже.
awk '{
sub(/" \/>\n<\/Module/,"",$2); ## substituting pattern space /> new line then </Module> to NONE in $2, here $2(field 2) will be not usual one as I have mentioned RS equals to none and FS equal to <Module>
gsub(/^\n| +<Name>|<\/Name>|<Property Name="| \/>|>$/,"",$2); ## globally substituting (a line which is starting with a new line OR <Name> starting with a space OR <\/Name> OR <Property Name=" OR \/ of $2 to NULL)
gsub(/" Value="/,"; ",$2); ## globally substituting (Value=") to "; " in field 2.
gsub(/" \/>/,",",$2); ## gobally substituting (" \/>) to (,) in $2 only.
print $2 ## printing the new edited $2 because we have done this editing as per OP's requirement so printing the new field 2.
}
' RS= FS="<Module>" file02 ## Mentioning RS(record separator) to NULL and FS as string <Module> and mentioning the Input_file then.
Вы пробовали команды grep/sed и аналогичные тексты? Задайте конкретный вопрос, если у вас возникли проблемы с этими командами. –
Еще лучше, используйте инструмент, предназначенный для обработки XML, например 'xmllint' или' xmlstarlet'. –