![删除空格和数字](https://linux22.com/image/108195/%E5%88%A0%E9%99%A4%E7%A9%BA%E6%A0%BC%E5%92%8C%E6%95%B0%E5%AD%97.png)
我只想删除这些
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