Various posts in other forums have suggested that the best way to use grep
to return a single line per file is using -m 1
, which is the --max-count
option. However, when I write the following line, I get only one file, not one line per file:
grep -m 1 "library" ./ -R
Returns a single file on a single line:
.//results/fig/fig_functions.R:# library(plyr)
Whereas
grep "library" ./ -R
Returns many files, each with multiple lines:
.//results/fig/fig_functions.R:# library(plyr)
.//results/fig/fig_functions.R:# library(grid)
.//src/rmd/genevese_params.html:library(sf)
.//src/rmd/genevese_params.html:library(raster)
[many more lines and files...]
I would like the command to return all files containing the text, but only return one line per file. Am I using grep
incorrectly or is there another way to do this?
-l
option:grep -lR "library" .