Bashを使用してテキスト内の他の単語から数字を抽出する方法(数字のみ)

Bashを使用してテキスト内の他の単語から数字を抽出する方法(数字のみ)

使用吹く、少なくとも1つの数字(数字は1つ以上の数字のみで構成されています)を含むテキストの行数を表示したいと思います。
また、検出された数字を線で表示したいと思います。テキストファイル example.txt の例は、必須出力とともに提供されます。

$ cat example.txt
Electronic mail is a method of exchanging digital messages between computer 
users; such messaging first entered substantial
use in the 1960s and by the 1970s had taken the form now recognised as email. 
These are spams email ids: 

08av , 29809, pankajdhaka.dav, 165 .

23673 ; meetshrotriya;  221965; 1592yahoo.in
[email protected]
[email protected]
[email protected]
[email protected]

[email protected]
These are incorrect:

065
kartikkumar781r2#
1975, 123

希望の出力:

Number of lines having one or more digits are: 4
Digits found:
29809
165
23673
221965
065
1975
123

ベストアンサー1

努力する:

printf '
Number of lines having one or more digits are: %d
Digits found:
%s
' "$(grep -Ecw '[[:digit:]]+' infile)" "$(grep -Eow '[[:digit:]]+' infile)"

おすすめ記事