-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
  • 326
  • 5
  • 24

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.

rubystallion
  • 2,083
  • 15
  • 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
  • 8,945
  • 8
  • 66
  • 87
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
  • 34,397
  • 6
  • 36
  • 56