LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-05-2019, 04:31 PM   #16
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,797

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550

Quote:
Originally Posted by TBotNik View Post
All,

I'm not very good at using cmd line to find strings in a file, normally using kfind, but not installable on the current box, so needing the right locate or find cmd to find files in a framework containing db queries so need to find the strings:
Code:
->query
or
->qry
using either the locate or find cmdline dmds.

Assuming search filtering should be using REGEX!

Searsh will be system wide using '*.php' and the subdirectory '/EM/'.

Cheers!

TBNK
A couple of methods:
Code:
$ find /EM -type f -iname '*.php -exec grep -l -E 'query|qry' {} \;
or
Code:
$ echo >> grep.strings
query
qry
^D
$ find /EM -type f -iname '*.php' -exec grep -l -f grep.strings {} \;
should do the trick.

If you have multiple "EM" subdirectores or it's not right under "/", search for those and pass the full path to each one to another find::
Code:
$ find / -type d -name EM | while read DIR
> do
>    find $DIR -type f -iname '*.php' -exec grep -l -E 'query|qry' {} \;
> done   
$
If you don't care about case, you can add the '-i' switch to the 'grep -l -E' commands.

HTH...

Last edited by rnturn; 12-05-2019 at 04:35 PM.
 
Old 12-11-2019, 10:32 AM   #17
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
All,

I need this as I have to record the usage, do edits and use git to merge duplicate files!

Cheers!

TBNK
 
Old 01-02-2020, 10:21 AM   #18
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
I realize this is an older thread, but the OP hasn't marked it as solved so I'll provide another solution as an alternative to rnturn's.
Quote:
Searsh[sic] will be system wide using '*.php' and the subdirectory '/EM/'.
This statement is confusing, by the way.

Solution #1:
Code:
# cd into the EV directory
cd EV

# use a combination of grep's recursive option and its "include file" filter.
# include '>' in the search pattern to ensure only methods are matched.
grep -R --include '*.php' -E '>(query|qry)'
Solution #2:
Code:
grep -R --include '*.php' -E '>(query|qry)' EV/
 
Old 01-02-2020, 02:10 PM   #19
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by individual View Post
I realize this is an older thread, but the OP hasn't marked it as solved so I'll provide another solution as an alternative to rnturn's.

This statement is confusing, by the way.

Solution #1:
Code:
# cd into the EV directory
cd EV

# use a combination of grep's recursive option and its "include file" filter.
# include '>' in the search pattern to ensure only methods are matched.
grep -R --include '*.php' -E '>(query|qry)'
Solution #2:
Code:
grep -R --include '*.php' -E '>(query|qry)' EV/
individual,

Getting the info correct I'm working with:
Code:
cd /path/EM
grep -R --include '*.php' -E '>(dbFetch|dbArray)' > /home/files/emdbqry_dump.txt
or
grep -R --include '*/EM/*.php' -E '>(dbFetch|dbArray)' > /home/files/emdbqry_dump.txt
but both cmds instantly produce an empty file.

Thanks! But still trying to perfect this cmd.

Cheers!

TBNK
 
Old 01-03-2020, 05:46 AM   #20
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
All,

cmd:
Code:
grep -R --include '*.php' -E '(dbFetch|dbArray)' > /home/files/emdbqry_dump.txt
Worked! Yeah! Knew I was close!

Got these results:
Code:
em_dio/em_dio.php:      /*                              Added methods dbExec, dbFetch, dbNRows, dbRes to allow for$
em_dio/em_dio.php:      /*                              Added methods db_Set_Vars, dbAdd, dbArray.  Added "Mode" t$
em_dio/em_dio.php:      function dbArray ( $sql, $mode=NULL, $connect=NULL ) {
em_dio/em_dio.php:               function dbFetch($db_res,$db_row) {
em_dio/em_dio.php:                  /*  Function: dbFetch()                                                */
em_dio/em_dio.php:               }           // end function dbFetch
em_stdio/em_stdio.php:  /* Added functions dbExec, dbFetch, dbNRows, dbRes to allow for query actions  */
em_stdio/em_io.php:     /* Added functions dbExec, dbFetch, dbNRows, dbRes to allow for query actions  */
As you can see it not only found the 2 methods/functions but also comments with the string being looked for.

Now back to my main function problem and finishing my script!

Last edited by TBotNik; 01-03-2020 at 05:55 AM.
 
Old 01-04-2020, 11:46 AM   #21
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,217

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
TBotNik: was this work that you were being paid to do?
 
Old 01-10-2020, 02:57 PM   #22
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
TBotNik: was this work that you were being paid to do?
dugan,

No my own things as Enterprise Modules is something I developed that is platform, language, etc. independent and developed it clear back in 94.

It just works out that it is also a perfect PHP framework, especially since PHP csn be compiled.

Cheers!

TBNK
 
  


Reply

Tags
bash, find, locate, strings


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
replace strings in a file using strings from another file xpto09 Linux - Newbie 3 01-28-2016 06:11 PM
BASH: replace strings in on file by the strings in another one cristalp Programming 5 10-28-2011 09:47 AM
[SOLVED] Searching and replacing strings in a file with strings in other files xndd Linux - Newbie 16 07-29-2010 02:40 PM
create an error table? finding strings, and counting... in bash elinenbe Programming 3 06-26-2008 03:49 PM
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration