How about:
I think your solution would report directories, for example. It also would report a file on a search for "goo" when the file had the word "good".
My example also has failings.
You decide. It all depends on the exact requirements for the script. Plus, you can script the same solution using multiple tools. In this case awk, grep, or even just plain bash.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
We ran across a need for this some time ago, and wrote a solution that has worked for us.
In between projects, we discuss how we should publish our code: our own website, sourceforge, girhub, as a post in a thread (as Corona688 has done here, for example, among others). No consensus so far, sigh.
We have agreed that we can at least post the documentation for our utilities in hopes that it may provide motivation for others to use approaches that have worked (at least for us).
So here are some details on our rapgrep -- this is clearly not a one-line suggestion
and the help :
Best wishes ... cheers, drl
Thanks a lot for your contributions, which I compared...
My solution was slowest, ( so I guess using exec within the find command is not very efficient ) and as you predicted, included files containing any character string, not just whole words. But this can be a requirement, actually.
... and disedorgue's solution caused a core dump as run, so I didn't try fiddling with it too much, as it's not my system ! In any case our production system has many non-linux machines, so bash options won't work.
Not sure where the code is for drl's solution, didn't find rapgrep on Bing either. What am I missing ?
Regards,
Moderator's Comments:
Please use CODE tags as required by forum rules!
---------- Post updated at 04:48 AM ---------- Previous update was at 03:56 AM ----------
Hi again,
You guys have opened my eyes regarding find . -exec... which I regularly use
I know this isn't strictly the post subject, but I just wanted to comment on the difference between
real 0m6,38s
and
real 2m15,43s !!!!!!!!!!!
Thanks for this revelation !
Last edited by rbatte1; 12-01-2016 at 06:45 AM..
Reason: Added ICODE tags.
The difference you are seeing is probably because your find . -exec grep ..... runs the grep command individually for each file. The use of xargs in my suggestion reduces the number of command calls and therefore the number of process spawned. It may not be the best way, but it works okay.
You might be able to use a + and the end of your -exec section of the find instead of the \;, but it depends on which version of find you have.
Be aware that times may vary depending on the number of files and their sizes, so searching a very few large files may be slow with my suggestion because it will potentially read the files twice.
Glad to have helped a bit this time, but do keep experimenting if the times get longer.
I have the file like this.
cat 123.txt
<p> <table border='1' width='90%' align='center' summary='Script output'> <tr><td>text </td> </tr> </table> </p>
I want to replace some tags and want the output like below. I tried with awk & sed commands. But no luck. Could someone help me on this?
... (4 Replies)
Hy there all. Im new here. Olso new to terminal & bash, but it seams that for me it's much easyer to undarsatnd scripts than an actual programming language as c or anyother languare for that matter.
S-o here is one og my home works s-o to speak.
Write a shell script which:
-only works as a... (1 Reply)
Hi,
Do anybody know how to print out only those record that column 1 is "a" , then followed by "b"?
Input file :
a comp92 2404242 2405172
b comp92 2405303 2406323
b comp92 2408786 2410278
a comp92 2410271 2410337
a comp87 1239833 1240418
b comp87... (3 Replies)
Hi, all:
I would like to search all files under "./" and its subfolders recursively to find out
those files contain both word "A" and word "B", and list the filenames finally.
How to realize that?
Cheers
JIA (18 Replies)
Hi
I have a script where the user calls it with arguments like so:
./import.sh -s DNSNAME -d DBNAME
I want to check that the database entered is valid by going through a passwd.ds file and checking if the database exists there.
If it doesn't, the I need to send a message to my log... (4 Replies)
Hi All,
I have a file like this,(This is a sql output file)
cat query_file
200000029
12345 10001
0.2 0
I want to fetch the values 200000029,10001,0.2 .I tried using the below code but i could get... (2 Replies)
Hi,
I am trying to find the content of file using grep and find command and list only the file names
but i am getting entire file list of files in the directory
find . -exec grep "test" {} \; -ls
Can anyone of you correct this (2 Replies)
I have a file that contains the following:
Mon Dec 3 15:52:57 PST 2o007: FAILED TO PROCESSED FILE 200712030790881200.TXT - exit code=107
Tue Dec 4 09:08:57 PST 2007: FAILED TO PROCESSED FILE 200712030790879200a.TXT - exit code=107
This file also has a lot more stuff since it is a log file.... (2 Replies)
Hi,
I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this?
Thanks for your help. (1 Reply)