YOU
YOU

Reputation: 333

regex grep filter with string

I have text like these :

div class="ls-icon ls-item " data-ctrdot="214752854">
div class="ls-icon ls-item " data-ctrdot="213523235">
div class="ls-icon ls-item " data-ctrdot="788746365">
div class="ls-icon ls-item " data-ctrdot="332532436">

and i want to export :

data-ctrdot="214752854">
data-ctrdot="213523235">
data-ctrdot="788746365">
data-ctrdot="332532436">

but i dont know why this

grep -o 'data-ctrdot="\w*'

does not work . Thanks

Upvotes: 0

Views: 108

Answers (2)

kojiro
kojiro

Reputation: 77167

If by does not work you mean it outputs this:

data-ctrdot="214752854
data-ctrdot="213523235
data-ctrdot="788746365
data-ctrdot="332532436

Instead of

data-ctrdot="214752854">
data-ctrdot="213523235">
data-ctrdot="788746365">
data-ctrdot="332532436">

Then yes, it's broken. But perhaps you could just inject the last two characters into the grep expression?

grep -o 'data-ctrdot="\w*">'

data-ctrdot="214752854">
data-ctrdot="213523235">
data-ctrdot="788746365">
data-ctrdot="332532436">

Upvotes: 3

anubhava
anubhava

Reputation: 786001

You can use:

awk '/data-ctrdot=/{print $NF}' file

Upvotes: 1

Related Questions