I have a file that contains lines like this
some thing <phrase>a phrase</phrase> some thing else <phrase>other stuff</phrase>
I need to replace all the spaces between <phrase>
tags with an underscore. So basically I need to replace every space that falls between >
and </
with an underscore. I've tried many different commands in sed, awk, and perl but haven't been able to get anything to work. Below are some of the commands I've tried.
sed 's@>\s+[</]@_@g'
perl -pe 'sub c{$s=shift;$s=~s/ /_/g;$s}s/>.*?[<\/]/c$&/ge'
sed 's@\(\[>^[<\/]]*\)\s+@\1_@g'
awk -v RS='\\[>^[<\]/]*\\]' '{ gsub(/\<(\s+)\>/, "_", RT); printf "%s%s", $0, RT }' infile
I've been looking at these 2 questions trying to modify the answers to use the characters I need.
sed substitute whitespace for dash only between specific character patterns
Can anyone please help?