如何只打印包含字母数字unix的文件中的数字

时间:2017-06-21 11:15:55

标签: linux shell unix

如何仅打印包含字母数字unix的文件中的数字 我的档案是: cat test1.txt

来自惠普资产管理器的

矩阵ID此行是此文件中的第一个大写行。 此行是此文件中的第一个小写行。 这条线具有大写字的所有第一个字符。

此行上方两行为空。 这是最后一行。

Sainadh 9876543210 YWC
avinash 9871234560 kvan
lalith 9875463210 mlp
sudgaeaed 9875645612 kkk
jknlnklm dasdad 9871239875
9879879876 uuojlx 987897654322
cknkzxnckl 9873456541 kkdlsd

Iwant o / p like

9876543210 
9871234560 
9875463210 
9875645612 
9871239875
987897654322
9879879876 
9873456541 

TIA

2 个答案:

答案 0 :(得分:2)

grep -Eo "\b[0-9]+\b" filename

[0-9]+表示1位或更多位数
并且\b \b内部仅匹配包含该值的行。

答案 1 :(得分:0)

grep -ow。[0-9] * test1.txt

  -o, --only-matching
          Print only the matched (non-empty) parts  of  a  matching  line,
          with each such part on a separate output line.
  -w, --word-regexp
          Select  only  those  lines  containing  matches  that form whole
          words.  The test is that the matching substring must  either  be
          at  the  beginning  of  the  line,  or  preceded  by  a non-word
          constituent character.  Similarly, it must be either at the  end
          of  the  line  or  followed by a non-word constituent character.
          Word-constituent  characters  are  letters,  digits,   and   the
          underscore.