I am using grep as follows
grep --include \*.org -ir "sunspot" -C 3 ./astron_aphys/solarsy/sun/helioseism/localhs/fhankel/
This gives me the filename for each matched line. How can I change the command to print the file name only once rather than having the same file name repeated at every line
kristinu, Please show your output. To obtain unique output, you can pipe the results from grep to
sort | uniq
or better yet
sort -u
commands.
Pipe your grep to this post processor
awk '$0=="--" {print; next} {fname=line=$0; sub(/[:-].*/,"",fname); sub(/.*[:-]/,"",line)} fname!=oldfname {print "File="fname; oldfname=fname} {print line}'