Try this little trick to coax grep
into thinking it is dealing with multiple files, so that it displays the filename:
grep 'pattern' file /dev/null
To also get the line number:
grep -n 'pattern' file /dev/null
More Related Contents:
- How can I grep for a string that begins with a dash/hyphen?
- Grep for literal strings
- Use grep –exclude/–include syntax to not grep through certain files
- How does grep run so fast?
- How to grep for the whole word
- Print lines in one file matching patterns in another file
- Using grep for multiple search patterns
- grep a tab in UNIX
- grep for special characters in Unix
- Grepping for exact words with UNIX
- Remove carriage return in Unix
- Canonical vs. non-canonical terminal input
- What does ^M character mean in Vim?
- How do I grep for all non-ASCII characters?
- Why is 1/1/1970 the “epoch time”?
- How to make grep only match if the entire line matches?
- Is there a Unix utility to prepend timestamps to stdin?
- How do I use the nohup command without getting nohup.out?
- How to do a mass rename?
- How to concatenate multiple lines of output to one line?
- Get last field using awk substr
- Unix:merge multiple CSV files with same header by keeping the header of the first file
- unix command line execute with . (dot) vs. without
- How to strip leading “./” in unix “find”?
- How to move or copy files listed by ‘find’ command in unix?
- How do I change a shell scripts character encoding?
- What are the dark corners of Vim your mom never told you about? [closed]
- Creating string of repeated characters in shell script [duplicate]
- Configure cron job to run every 15 minutes on Jenkins
- In a unix shell, how to get yesterday’s date into a variable?