简体   繁体   中英

How can I output the result of find and grep as filename => found

How can I combine the result of commands find and grep in the format: filename: => string ?

For example, find . -maxdepth 2 -type f -name .env -exec grep 'CURRENT_ENV' {} \\; find . -maxdepth 2 -type f -name .env -exec grep 'CURRENT_ENV' {} \\; The command will display me the line when CURRENT_ENV string found, eg CURRENT_ENV=staging . I want to modify the output in the follow way: ./site1.com: CURRENT_ENV=staging .

I can't understand How can I reach that. Is it possible?

  -H, --with-filename Print the file name for each match. This is the default when there is more than one file to search. 

http://man7.org/linux/man-pages/man1/grep.1.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM