删除空格和数字

删除空格和数字

我只想删除这些

0.10
0.10
0.10
0.10
1.4
1.4
1.4
2.7

但不要删除这些行和数字

activemq 5.6.0+dfsg1-4+deb8u2
akonadi-backend-mysql 1.13.0-2+deb8u2
akonadi-backend-postgresql 1.13.0-2+deb8u2
akonadi-backend-sqlite 1.13.0-2+deb8u2
akonadi-server 1.13.0-2+deb8u2
apache2 2.4.10-10+deb8u5
apache2.2-bin 2.4.10-10+deb8u5
apache2.2-common 2.4.10-10+deb8u5
apache2-bin 2.4.10-10+deb8u5
apache2-data 2.4.10-10+deb8u5
apache2-dev 2.4.10-10+deb8u5
apache2-doc 2.4.10-10+deb8u5
apache2-mpm-event 2.4.10-10+deb8u5
apache2-mpm-itk 2.4.10-10+deb8u5
apache2-mpm-prefork 2.4.10-10+de

答案1

grep -e '^$' -e '^[.]$' -e '[.].*[.]' -e '[^0-9.]' yourfile

在这里,我们逐步过滤我们想要保留的行的性质:

a) thoroughly empty lines,
b) lines that are exactly a dot,
c) lines that comprise at least 2 dots,
d) finally, lines that have at least 1 nondigit &/or 1 dot. (Note: a solitary dot
   has already been filtered out by step-b) earlier.)

答案2

如果您只想删除以任何数字开头的任何行,您可以尝试:

grep -v "^[0-9]" filename

相关内容