2017-04-20 3 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の何か43,270のような何か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 
関連する問題