2017-04-20 60 views
0

是否有可能grep某種程度上來自文件的所有價格並列出輸出?價格以「$」開頭,可能包含數字,「,」和「。」。grep從文件的所有價格

我試過最好的解決方案,從this question,但他們輸出包含價格的所有文件或整個字符串。

我使用的圖案是簡單的:\$

在網絡上的頁面欲到grep:網頁源代碼的http://www.ned.org/

實施例:

<p><strong>Better Understanding Public Attitudes and Opinions</strong> 
</p> 
<p>Democratic Ideas and Values</p> 
<p>$43,270</p> 
<p>To monitor and better understand public views on key social, political, and economic developments. Citizens’ opinions will be tracked, documented, and studied ahead of and after the country’s September 2016 parliamentary elections. The results and accompanying analysis will be disseminated through print and electronic publications, a website, and independent media.</p> 
<p><strong> </strong></p> 

我想從該輸出一片html的東西像是4470或可能是43270.只是爲了懶寫一個解析器:)

+1

至少你可能會表現出一定的輸入例如 – RomanPerekhrest

+1

@RomanPerekhrest,確保萬無一失。對不起,以前沒有這樣做。 – kelin

回答

2

這樣的東西似乎s到正常工作爲我的測試:

$ echo "$prices" 
tomato $30.10 
potato $19.1 
apples=$2,222.1 
oranges:$1 
peach="$22.1",discount 10%,final price=$20 

$ egrep -o '\$[0-9]+([.,][0-9]+)*' <<<"$prices" 
$30.10 
$19.1 
$2,222.1 
$1 
$22.1 
$20 

實際測試你的網頁:

$ links -dump "http://www.ned.org/region/central-and-eastern-europe/belarus-2016/" |egrep -o '\$[0-9]+([.,][0-9]+)*' 
$43,270 
$25,845 
$55,582 
$14,940 
$44,100 
$35,610 
$54,470 
$60,200 
$33,150 
$15,720 
$35,160 
$45,500 
$72,220 
$26,330 
$53,020 
$27,710 
$22,570 
$40,145 
#more prices following bellow 
相關問題