Is there a quick way to search all text files for a string?
By "text file" I mean ASCII files, like log files, config files etc, but excluding binaries like executables, database files, etc?
What I want is something like: find / -type a -exec grep 192.168.100.1 {} ; .. or similar, except that I made up "-type a" for ascii.
(I'm trying to find all places that an IP address is mentioned so that I can change ones that need to be changed.)
On Thu, 2016-06-30 at 11:14 +0100, Mark Rogers wrote:
Is there a quick way to search all text files for a string?
By "text file" I mean ASCII files, like log files, config files etc, but excluding binaries like executables, database files, etc?
What I want is something like: find / -type a -exec grep 192.168.100.1 {} ; .. or similar, except that I made up "-type a" for ascii.
(I'm trying to find all places that an IP address is mentioned so that I can change ones that need to be changed.)
Given that the "file" command can recurse through directories, I would have thought there was mileage in something like;
grep '192.168.1.1' `file -r | grep ascii | awk -F: {print $1}`
Yes, yes, I know this is hideous and an 'xargs' would be good in there somewhere, but it's just a suggestion to start from!
On 30 June 2016 at 11:23, Huge huge@huge.org.uk wrote:
Given that the "file" command can recurse through directories,
file -r didn't seem to work for me. (-r = raw, not recurse).
But it did lead me to the horrible messy but functional:
grep 192.168.1.1 `file $(find etc -type f) | grep ASCII | sed 's#:.*##'`
So thanks!
Improvements welcome though (as a learning exercise).
On Thu, 2016-06-30 at 11:56 +0100, Mark Rogers wrote:
On 30 June 2016 at 11:23, Huge huge@huge.org.uk wrote:
Given that the "file" command can recurse through directories,
file -r didn't seem to work for me. (-r = raw, not recurse).
W-e-e-e-e-e-e-lll. I meant '-R', but that doesn't do what I thought it did anyway!
But it did lead me to the horrible messy but functional:
grep 192.168.1.1 `file $(find etc -type f) | grep ASCII | sed 's#:.*##'`
So thanks!
You're welcome.
Improvements welcome though (as a learning exercise).
-ditto-
On Thu, Jun 30, 2016 at 11:14:00AM +0100, Mark Rogers wrote:
Is there a quick way to search all text files for a string?
By "text file" I mean ASCII files, like log files, config files etc, but excluding binaries like executables, database files, etc?
What I want is something like: find / -type a -exec grep 192.168.100.1 {} ; .. or similar, except that I made up "-type a" for ascii.
(I'm trying to find all places that an IP address is mentioned so that I can change ones that need to be changed.)
Does "grep -r -I 192.168.100.1 /" not do what you want?
J.
On 30 June 2016 at 12:16, Jonathan McDowell noodles@earth.li wrote:
Does "grep -r -I 192.168.100.1 /" not do what you want?
Ah, yes it probably does, now that I see that as an upper-case "i" rather than a lower-case "L"!
Well I thought there should be a better way, and now I just feel a bit daft for not spotting it...
Mark
On 30/06/16 12:16, Jonathan McDowell wrote:
[SNIP]
Does "grep -r -I 192.168.100.1 /" not do what you want?
That won't work if there are lots and lots of files to search...
Cheers, Laurie.
On Thu, Jun 30, 2016 at 01:23:43PM +0100, Laurie Brown wrote:
On 30/06/16 12:16, Jonathan McDowell wrote:
Does "grep -r -I 192.168.100.1 /" not do what you want?
That won't work if there are lots and lots of files to search...
Why not?
J.
On 30/06/16 13:37, Jonathan McDowell wrote:
On Thu, Jun 30, 2016 at 01:23:43PM +0100, Laurie Brown wrote:
On 30/06/16 12:16, Jonathan McDowell wrote:
Does "grep -r -I 192.168.100.1 /" not do what you want?
That won't work if there are lots and lots of files to search...
Why not?
Because you it can fail with an "Argument list too long" message. It's a right pain, but using xargs as I previously suggested avoids that.
Cheers, Laurie.
On Thu, Jun 30, 2016 at 02:21:23PM +0100, Laurie Brown wrote:
On 30/06/16 13:37, Jonathan McDowell wrote:
On Thu, Jun 30, 2016 at 01:23:43PM +0100, Laurie Brown wrote:
On 30/06/16 12:16, Jonathan McDowell wrote:
Does "grep -r -I 192.168.100.1 /" not do what you want?
That won't work if there are lots and lots of files to search...
Why not?
Because you it can fail with an "Argument list too long" message. It's a right pain, but using xargs as I previously suggested avoids that.
"-r" means recursively grep; you pass a single directory to grep in the same way you pass a single directory to find in your example. The number of files under that directory is irrelevant.
J.
On 30/06/16 14:55, Jonathan McDowell wrote:
On Thu, Jun 30, 2016 at 02:21:23PM +0100, Laurie Brown wrote:
On 30/06/16 13:37, Jonathan McDowell wrote:
On Thu, Jun 30, 2016 at 01:23:43PM +0100, Laurie Brown wrote:
On 30/06/16 12:16, Jonathan McDowell wrote:
Does "grep -r -I 192.168.100.1 /" not do what you want?
That won't work if there are lots and lots of files to search...
Why not?
Because you it can fail with an "Argument list too long" message. It's a right pain, but using xargs as I previously suggested avoids that.
"-r" means recursively grep; you pass a single directory to grep in the same way you pass a single directory to find in your example. The number of files under that directory is irrelevant.
Well, all I can say is that I was bitten by this a long time ago on a Gentoo box, using "-r", and the only way around it was to use xargs. Your mileage may vary, as the Yanks say, but if you google grep and "Argument list too long" you will find many, many people asking how to fix it, and xargs is the consistent answer.
I've never had a problem since and I've been using Linux for well over 20 years.
You use what works for you, that's the beauty of Linux.
Cheers, Laurie.
On Thu, Jun 30, 2016 at 02:21:23PM +0100, Laurie Brown wrote:
On 30/06/16 13:37, Jonathan McDowell wrote:
On Thu, Jun 30, 2016 at 01:23:43PM +0100, Laurie Brown wrote:
On 30/06/16 12:16, Jonathan McDowell wrote:
Does "grep -r -I 192.168.100.1 /" not do what you want?
That won't work if there are lots and lots of files to search...
Why not?
Because you it can fail with an "Argument list too long" message. It's a right pain, but using xargs as I previously suggested avoids that.
It very rarely happens to me nowadays though, in fact I don't think I've seen that error in years.
On Thu, Jun 30, 2016 at 12:16:07PM +0100, Jonathan McDowell wrote:
On Thu, Jun 30, 2016 at 11:14:00AM +0100, Mark Rogers wrote:
Is there a quick way to search all text files for a string?
By "text file" I mean ASCII files, like log files, config files etc, but excluding binaries like executables, database files, etc?
What I want is something like: find / -type a -exec grep 192.168.100.1 {} ; .. or similar, except that I made up "-type a" for ascii.
(I'm trying to find all places that an IP address is mentioned so that I can change ones that need to be changed.)
Does "grep -r -I 192.168.100.1 /" not do what you want?
That was exactly what I was going to ask. :-)
On 30/06/16 11:14, Mark Rogers wrote:
Is there a quick way to search all text files for a string?
By "text file" I mean ASCII files, like log files, config files etc, but excluding binaries like executables, database files, etc?
What I want is something like: find / -type a -exec grep 192.168.100.1 {} ; .. or similar, except that I made up "-type a" for ascii.
(I'm trying to find all places that an IP address is mentioned so that I can change ones that need to be changed.)
This is what I use:
#### wild card grep:
find [dir] -type f | xargs grep -i "string"
#### find filenames containing string:
find [dir] -type f | xargs grep -liH "string"
Cheers, Laurie.
On 30/06/2016 13:22, Laurie Brown wrote:
find [dir] -type f | xargs grep -i "string"
Also: find [dir] -type f -print0 | xargs -0 grep -i "string" This delimits names with ASCII null, so can handle filenames with embedded spaces, newlines and other weirdness.
On 04/07, Brett Parker wrote:
On 30 Jun 13:22, Laurie Brown wrote:
find [dir] -type f | xargs grep -liH "string"
Or, getting rid of the useless pipe, and using any modern version of find:
find [dir] -type f -exec grep -liH "string" {} +
I likely missed some context by not bothering to read the whole thread, but why not:
grep -rliH "string" [dir]
?
Steve
On Mon, 4 Jul 2016 15:36:04 +0100 Steve Engledow steve@offend.me.uk wrote:
On 04/07, Brett Parker wrote:
On 30 Jun 13:22, Laurie Brown wrote:
find [dir] -type f | xargs grep -liH "string"
Or, getting rid of the useless pipe, and using any modern version of find:
find [dir] -type f -exec grep -liH "string" {} +
I likely missed some context by not bothering to read the whole thread, but why not:
grep -rliH "string" [dir]
?
find: invalid predicate `-rliH'
On 05/07, Chris Walker wrote:
Steve Engledow steve@offend.me.uk wrote:
grep -rliH "string" [dir]
find: invalid predicate `-rliH'
find != grep
On 4 July 2016 at 15:36, Steve Engledow steve@offend.me.uk wrote:
I likely missed some context by not bothering to read the whole thread, but why not:
grep -rliH "string" [dir]
The only bit you missed was the same suggestion from Mr McDowell, and yes it's the right (and simple) answer that I was missing!
All the other ways to work around it with find were interesting, but grep -rl was definitely the key.
On Thu, 7 Jul 2016 10:40:45 +0100 Mark Rogers mark@more-solutions.co.uk wrote:
On 4 July 2016 at 15:36, Steve Engledow steve@offend.me.uk wrote:
I likely missed some context by not bothering to read the whole thread, but why not:
grep -rliH "string" [dir]
The only bit you missed was the same suggestion from Mr McDowell, and yes it's the right (and simple) answer that I was missing!
All the other ways to work around it with find were interesting, but grep -rl was definitely the key.
I have an app on my Sailfish phone and using these text searches I've been looking for any files related to it so that I can modify the QML files.
Normally the files are /home/nemo.local/share/harbour-<appname> but they're not. So using the various search suggestions I've been searching but without success.
Can anybody suggest why they're not working and also a way to find the files?
On Thu, 2016-07-07 at 10:40 +0100, Mark Rogers wrote:
grep -rl was definitely the key.
Some of us are older than the '-r' switch to 'grep'.
:o)
On 09-Jul-2016 15:36:25 Huge wrote:
On Thu, 2016-07-07 at 10:40 +0100, Mark Rogers wrote:
grep -rl was definitely the key.
Some of us are older than the '-r' switch to 'grep'.
:o)
From which it would follow that some of us haven't read 'man grep'
for years :o):o) Ted.
-- Today is Setting Orange, the 44th day of Confusion in the YOLD 3182 I don't have an attitude problem. If you have a problem with my attitude, that's your problem.
------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@wlandres.net Date: 09-Jul-2016 Time: 23:08:27 This message was sent by XFMail -------------------------------------------------