1

を使用してファイルをダウンロードしようとしていますがwget、進行状況をログ ファイルに保存したいと考えています。

wget http://unfccc.int/resource/docs/convkp/kpeng.pdf -O amit.pdf 2> amit.log

これはwgetが返すものです:

Connecting to unfccc.int (unfccc.int)|62.225.2.55|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 76721 (75K) [application/pdf]
Saving to: `amit.pdf'

 0K .......... .......... .......... .......... .......... 66% 2.29M 0s
50K .......... .......... ....                            100% 9.41M=0.02s

2013-08-28 12:24:32 (3.06 MB/s) - `amit.pdf' saved [76721/76721]

grep を使用して、最後の行からパーセンテージ値を取得したいと考えています。これは、機能しない上記のコマンドと一緒に使用したものです。

| grep "(\d+(\.\d+)?(?=%)" amit.log

sed と awk を使用せずに grep のみを使用することは可能ですか?

4

2 に答える 2

3
  1. パターンに不一致が含まれています(
  2. grepPCRE を使用していることを伝える必要があります。
  3. ファイルにリダイレクトSTDERRしているので、パイプを使用してgrepもあまり意味がありません。代わりに、リダイレクトSTDERRSTDOUTて出力をパイプします。

試す:

grep -oP "(\d+(\.\d+)?(?=%))"

パイプを使用する場合は、次のように言います。

wget http://unfccc.int/resource/docs/convkp/kpeng.pdf -O amit.pdf 2>&1 | grep -oP "(\d+(\.\d+)?(?=%))"

編集:stderrファイルに記録する必要がある場合は、次のように言います。

wget http://unfccc.int/resource/docs/convkp/kpeng.pdf -O amit.pdf 2>&1 | tee amit.log | grep -oP "(\d+(\.\d+)?(?=%))"
于 2013-08-28T08:33:04.587 に答える