9

Utility to search file contents, open it, and go to relevant line

view full story
linux-howto

http://superuser.com – I’m looking for a tool that given a search string and some set files, would search every one of them for said string, and if it finds it, open the file and go to that line. Maybe this could be better explained with the following snippet search() { for file in $(find . -type f); do contains=$(cat "${file}" | grep -n "$1") [[ -n "${contains}" ]] && echo "${file}" done } This is a simplified version — it will only print the filename of matching files and search every file in the current directory, but it works. We could extend it and go to the relevant line by putting (HowTos)