문제

I would like to extract data from a document with VIM using regular expression but I only need the exact match and not the hole line. Basically just copy what :%s would replace.

Simple example:

<td>sell:8092.23</td>
<td>buy:850.00</td>
<td>sell:99.99</td>

... and extract the numbers:

8092.23
850.00
99.99

Is this possible in VIM and if how? Thanks in advance.

도움이 되었습니까?

해결책

try this:

%s/\v.{-}([0-9.]+).*/\1/

다른 팁

Use a regular expression with anchors to the beginning and end of the line, do grouping to keep the numbers and replace the whole line with it. Run following command from the shell and it will create a new file output.txt with the numbers leaving the input file unmodified:

vim -u NONE -N -c '
    set backup |
    %s/\v^\D+(\d+\.\d*).*$/\1/ |
    saveas! output.txt |
    q!
' infile
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top