grep 在给定的行上运行 n 个或多个周期

ixt*_*lix 3 grep text-processing

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

$ echo "there's. someone on the wing. some. thing." | grep -stuFF [[:idunno:]]{4,}
there's. someone on the wing. some. thing.
Run Code Online (Sandbox Code Playgroud)

我试过,盲目摸索:

grep -P [[.]]{\4,\} textfile
grep -P \.{\4,\} textfile
Run Code Online (Sandbox Code Playgroud)

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

grep -P [[:punct:]]{\4,\} textfile
Run Code Online (Sandbox Code Playgroud)

[[: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 signi?can$
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.; Ri?, 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;
Run Code Online (Sandbox Code Playgroud)

请注意,这些行中的第一行包含 10 个句点。

小智 9

grep -E '(.*\.){4}' textfile
Run Code Online (Sandbox Code Playgroud)

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