Get 'Grep' To Not Output File Name - Unix-StackExchange
Get 'Grep' To Not Output File Name - Unix-StackExchange
When I use grep -o to search in multiple files, it outputs each result prefixed with the file name.
How can I prevent this prefix? I want the results without the file names.
57
grep
Share Improve this question Follow edited May 20, 2015 at 21:52 asked May 20, 2015 at 14:25
Gilles 'SO- stop being Ram Rachum
evil' 1,755 2 16 19
848k 199 1.8k
2.3k
3 From man grep -h, --no-filename Suppress the prefixing of filenames on output when multiple files
are searched. – rahul May 20, 2015 at 14:29
With the GNU implementation of grep (the one that also introduced -o ) or compatible, you can
use the -h option.
86
-h, --no-filename
Suppress the prefixing of file names on output. This is the
default when there is only one file (or only standard input) to
search.
With other implementations, you can always concatenate the files with cat and grep that
output:
https://unix.stackexchange.com/questions/204607/get-grep-to-not-output-file-name 1/2
11/22/24, 10:27 PM Get `grep` to not output file name - Unix & Linux Stack Exchange
(basic regexps like with grep without -E . Many sed implementations now also support a -E
option for extended regexps).
Share Improve this answer Follow edited Nov 29, 2022 at 16:21 answered May 20, 2015 at 14:29
Stéphane Chazelas sergut
564k 96 1.1k 1.6k 2,059 15 11
Note that the option --no-filename doesn't work with git grep.
Share Improve this answer Follow answered Nov 29, 2022 at 15:53
Paul Rougieux
211 3 9
https://unix.stackexchange.com/questions/204607/get-grep-to-not-output-file-name 2/2