The file contains the following line
google.friendconnect
I got the line from the following command
cat * | grep google
However, I do not know its location.
How can you get the precise location of the file without Ack?
The file contains the following line
google.friendconnect
I got the line from the following command
cat * | grep google
However, I do not know its location.
How can you get the precise location of the file without Ack?
Try the -H flag for grep. Also, don't use cat there, please. It isn't necessary.
grep -H google *
To clarify, the -H flag forces grep to print the filename. After thinking it over, I remembered that the -H flag is the default when you search more than one file. So, in this case it's redundant. Andy's answer is really simpler and right.
For the general class of problem you're describing, to find the file you could run
grep -r 'google.friendconnect' /
Where ‘/‘ would be whatever directory path you want to search. This will recursively search all files in that directory tree for that string. The specific command presented will take a while, and will produce a lot of ‘Permission Denied’ errors unless you run it as root. Since it will be search proc, var, sys, and other users home directories. Another useful option to grep that you probably also want is ‘-n’. That will also print out the line number of the file that matched. Such as,
grep -n 'google.friendconnect' *
testfile:3:google.friendconnect
I find that 90% of the time I use the options ‘irn’ for grep: case insensitive, recursive, and print line numbers.
grep google *
(instead of using cat, give grep a list of file names and it will print the name of the files matching when it prints the lines)
An optimal way to search the string in all files under a directory to print matching files with line numbers on the matched line would look like this from the base directory.
grep -Hn <string_of_interest> `find . -type f`
That is without using AWK (which is what you meant i guess).