简体   繁体   中英

How can I format the output of “grep”?

I have this grep command:

grep -e PIPPO -e PLUTO -e TOPOLINO *.csv >> result.txt

I want the output to have this format:

path of file, row of file, text found

Any suggestions?

You need to do:

grep -Hn -e PIPPO -e PLUTO -e TOPOLINO *.csv >> result.txt

You can run the grep in a different directory if you want the full path:

cd /
grep -Hn -e PIPPO -e PLUTO -e TOPOLINO /your/path/*.csv >> result.txt

If you want to only show the matching parts add the -o parameter to grep:

grep -Hno -e PIPPO -e PLUTO -e TOPOLINO *.csv >> result.txt

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