SED remove white space between characters
I have an xml file whose lines should look like this:
<item id=""><myname>FIRST NAME</myname><myurl>http://etc.com</myurl></item>
I can easily replace the " myurl="
below to make the line look like the one above.
<item id=""><myname>FIRST 开发者_Go百科NAME" myURL="http://etc.com</myurl></item>
Unfortunately, most of them look like this, with different amounts of white space in b/t:
<item id=""><myname>FIRST NAME"
myURL="http://etc.com</myurl></item>
I can't seem to get a working SED replace for whitespace in b/t characters
Is regex 's/ */ /g'
what you're looking for?
For all strings of two or more spaces, this substitutes a single space.
sed '/myname>.*\"\s*$/N;s|\"\s*\n*\s*myURL=\"|</myname><myurl>|' file.xml
This first tests if the line is incomplete. If it is, it places the next line into the pattern space. In either case, it replaces the original text with the desired text.
BTW, if anyone can tell me a way to match a newline in the pattern space in a character set I would appreciate it. For example, [\s\n]*
instead of \s*\n*\s*
in the above expression.
input:
<item id=""><myname>FIRST NAME" myURL="http://etc.com</myurl></item>
<item id=""><myname>FIRST NAME"
myURL="http://etc.com</myurl></item>
<item id=""><myname>FIRST NAME" myURL="http://etc.com</myurl></item>
output:
<item id=""><myname>FIRST NAME</myname><myurl>http://etc.com</myurl></item>
<item id=""><myname>FIRST NAME</myname><myurl>http://etc.com</myurl></item>
<item id=""><myname>FIRST NAME</myname><myurl>http://etc.com</myurl></item>
精彩评论