简体   繁体   中英

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

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">

您可以使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM