0% found this document useful (0 votes)
31 views

Get 'Grep' To Not Output File Name - Unix-StackExchange

Get `grep` to not output file name - Unix-StackExchange

Uploaded by

Sathi Natarajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Get 'Grep' To Not Output File Name - Unix-StackExchange

Get `grep` to not output file name - Unix-StackExchange

Uploaded by

Sathi Natarajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/22/24, 10:27 PM Get `grep` to not output file name - Unix & Linux Stack Exchange

Get `grep` to not output file name


Asked 9 years, 6 months ago Modified 1 year, 11 months ago Viewed 52k times

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

2 Answers Sorted by: Highest score (default)

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:

cat ./*.txt | grep regexp

Or use sed or awk instead of grep :

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

awk '/regexp/' ./*.txt

(extended regexps like with grep -E ).

sed '/regexp/!d/' ./*.txt

(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

With git grep , use the -h option to suppress file names:

2 git grep -h <pattern>

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

You might also like