-1

Lets say I have a line like this:

<group description="" name="voice_guidance" comment="Missing description!" status="0">

I wish to grep with a bash script only the comment saying:

Missing description!

Bert
  • 347
  • 7
  • 25

3 Answers3

3

If you only want the comment, you can use this: grep -Po 'comment="\K[^"]*'

\K means to only output the part following from there and then all the non-quote characters following are output.

Johannes Riecken
  • 2,301
  • 16
  • 17
1

You can use straightforward solution:

grep '"Missing description!"' filename.html

Where filename.html is a target file.

Here is an example output:

grep file

P.S. In such when I see HTML and RegEx both present in the same question, I recommend to read this answer: https://stackoverflow.com/a/1732454/5091346

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
1

If you can't use the perl-regexp (-P) in @rubystallion's fine answer, use:

$ grep -o "comment=\"[^\"]\+" file | grep -o "[^\"]\+$"
Missing description!
James Brown
  • 36,089
  • 7
  • 43
  • 59