grep 在给定行上查找 n 个或多个句点

grep 在给定行上查找 n 个或多个句点

我希望能够任意匹配包含很多句点的行,如下所示:

$ echo "there's. someone on the wing. some. thing." | grep -stuFF [[:idunno:]]{4,}
there's. someone on the wing. some. thing.

我盲目摸索地尝试过:

grep -P [[.]]{\4,\} textfile
grep -P \.{\4,\} textfile

然后尝试了一些我知道在某种程度上会起作用的东西

grep -P [[:punct:]]{\4,\} textfile

[[:punct:]]{\4,\}令人失望的是,我只找到了很多我想让 grep 错过的行,这样我就可以扭转命令并执行grep -v.

即使这样做也grep -P '\.{4,}'不会返回我试图 grep 的行,如下所示:

    Sullivan, G.R. Tetrahedron Lett. 1971, 223; Pascal, Jr., R.A.; Winans, C.G.; Van Engen, D. J. Am. Chem.
compounds (i.e., shielding and deshielding of nuclei) can be measured by a simple
Plavic, D.; Babic, D.; Nikolic, S.; Trinajstic, N. Gazz. Chim. Ital., 1993, 123, 243.
Hess, Jr., B.A.; Schaad, L.J. J. Am. Chem. Soc. 1971, 93, 305.
as N-oxides or pyridinium ions are still aromatic. However, for nitrogen heterocycles there are more significan$
given in Coulson, C.A.; Streitwieser, Jr., A. A Dictonary of p Electron Calculations, W.H. Freeman, San
Hydrocarbons, Elsevier, NY, 1987; Clar, E. Polycyclic Hydrocarbons, 2 vols., Academic Press, NY, 1964.
Zhang, J.; Ho, D.M.; Pascal Jr., R.A. J. Am. Chem. Soc. 2001, 123, 10919.
See Herndon, W.C.; Ellzey Jr., M.L. J. Am. Chem. Soc. 1974, 96, 6631.
Dauben Jr., H.J.; Rifi, M.R. J. Am. Chem. Soc. 1963, 85, 3041; also see Breslow, R.; Chang, H.W. J. Am
1973, 1, 29; Kolomnikova, G.D.; Parnes, Z.N. Russ. Chem. Rev. 1967, 36, 735; Harmon, K.H., in Olah,
Bertelli, D.J.; Andrews, Jr., T.G. J. Am. Chem. Soc. 1969, 91, 5280; Bertelli, D.J.; Andrews Jr., T.G.;
Nikitina, T.V. Organomet. React., 1972, 4, 163; Bublitz, D.E.; Rinehart Jr., K.L. Org. React., 1969, 17, 1;

请注意,第一行包含 10 个句点。

答案1

grep -E '(.*\.){4}' textfile

这将匹配一行中至少 4 个句点,无论是否分隔。

相关内容