0

I am tying to grep <span class="c7"> from the below

<span class="c7"></span>

I am trying:

$ echo '<span class="c7"></span>'| grep -o "<span.*[^>]>"
<span class="c7"></span>

I am getting the above. So how to get only <span class="c7">

0
echo '<span class="c7"></span>'| grep -o "<span[^>]*>"

Your .* is greedy, it matched the first > and beyond. My [^>]* is also greedy, but it cannot match anything that includes >, so > in the pattern matches the first occurrence of > in the input for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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