Artificial intelligent assistant

How to use find and grep effectively together To find which files in the current directory contains specific string I would command `find . -type f -print0 | xargs -0 grep -ial <word>`. However this only shows path to file. How do I print the result in format, which prints path to file, line number(s), the matching line(s) (limited by parameter) with n heading and tailing lines, and newline before next result? What is the best resource to learn power use and tips of linux search and text manipulation tools?

grep -iarn -C3 word .


This will search the current directory and all subdirectories (just like your `find . -type f -print0` command), and show you the lines in those files matching "word" with three leading and trailing lines of context, and with the filename and line numbers labeling each line.

Instead of a blank line between matches, `grep` gives you pairs of lines with only `--` on them. If you really need a blank line because you are feeding the output of this to some other program, you can use this version:


grep -iarn -C3 word . | uniq | sed -e 's/^--$//'


As far your question on how to learn power tips, the Unix `man` pages are fairly dry reading, but skimming through the `man` page for some of the common tools is very educational. I also in particular recommend learning Perl if you do a significant amount of text manipulation in Linux or UNIX.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 344b0d5d9027723d0ebdd30608bfafc0