Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

here is a sample for my text file:

<w:r w:rsidR="00D171FD">
<w:t xml:space="preserve">
This is a sample text </w:t>
<w:highlight w:val="green"/>
<w:r w:rsidR="00D171FD">
<w:color w:val="FF0000"/>
Sample text</w:t>

The problem is that I need both the pure text and the following tags only:
color w:val="FF0000"
highlight w:val="green"

How can this be done?

share|improve this question
Could you post your expected output from sed or awk? You might be better of with a xml parser for this, see e.g. – N.N. Mar 8 '13 at 16:34
I think I'm gonna make a script to do it, Thanks. – Mina Mohsen Mar 8 '13 at 17:06

With the above command line it will function if you will never have those expression as text:

  1. <w:
  2. \>

The command line is:

cat Myfile.txt  | grep -E "color w:val=|highlight w:val=" | sed s/"<w:"/""/g | sed s/"\/>"/""/g


  • grep -E, --extended-regexp PATTERN
    Interpret PATTERN as an extended regular expression
  • | logical OR inside the PATTERN of grep
  • | pipe symbol in shell environment
  • sed s/"<w:"/""/g substitutes globally (everywhere) "<w:" with empty string ""

Note: it's possible to write sed in many other way and in a more compact way. I think so is didactic and can be used in a more wide range of possibility when is needed to substitute an expression with another.

This is the output:

highlight w:val="green"  
color w:val="FF0000"  
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.