search using single & double quotes of mltple value in each programs

princesslemonad

New Member
Hi,

I'm a newbie in progress 4GL and I'm creating a program that searches the 500 items (value) in each programs that reference it.

For example when I search for the code_fldname value (500 items) in programs, I need to search using double quotes and single quotes.

Below are examples of searching for the values and the results. Any idea is greatly appreciated. Thank you in advance.


“opsys” (matches found. Used for code_mstr query, add program to list)
M:\absw.t(185): and code_fldname = "opsys"
M:\absw.t(286): and code_mstr.code_fldname = "opsys"
M:\podw.t(61): and code_fldname = "opsys"
M:\soconf.t(206): CODE_mstr.CODE_fldname = "opsys"
M:\soconf.t(218): CODE_mstr.CODE_fldname = "opsys"
M:\soconf.t(1382): code_mstr.code_fldname = "opsys"

“opsys” (matches found. Used for code_mstr query, add program to list)
M:\xxautoship2.p(1439): AND code_fldname = 'opsys'
M:\xxautoship2.p(1452): and code_fldname = 'opsys'
M:\xxsqlpro-aud.p(80): and code_fldname = 'opsys'
M:\xxsqlpro-aud.p(90): and code_fldname = 'opsys'
M:\xxsqlpro.p(69): AND code_fldname = 'opsys'
M:\xxsqlpro.p(82): and code_fldname = 'opsys'
M:\xxsqluli1.p(92): and code_fldname = 'opsys'


“actype” (no matches found)

‘actype’ (no matches found)










[TABLE="width: 113"]
[TR]
[TD="width: 151, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][TABLE="width: 151"]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
 
Surely the best idea is to use TextPad? It has a find in files option that takes regular expressions. So your search would be something like
Code:
['"].opsys['"].

You'd have to check the help file for the exact syntax - I'm just guessing. But no use re-inventing the wheel IMO.
 
Thanks Cringer.

But I'm not familiar yet with Textpad. Do I have to put a progress procedure also on that application? Anyways, I have already extracted all the programs that reference to the table using a certain fieldname (below is my procedure. It disregards whether the value is declared using double quote or single quote).


repeat:
pause 0 before-hide.
import stream strm1 xcodefldname.
unix silent grep -l value(xcodefldname) C:\windows\devapps\* >
code_temp.out.
input stream strm2 from code_temp.out.
repeat:
import stream strm2 xprogname.

But the user would like to get the result as per my example below. The problem is there are multiple items/value of fieldname that reference the table for each programs (.p).
 
If you are on Windows you could use Copernic. I found this tool very handy.

For UNIX - I wrote this script "sometime" ago that searchs for a string (table / field/ database / hard-coded values etc) in all program files in the source directory. It does something very simliar to what you did. It creates an output file with list of matches. I then read it into a temp-table and filter out the duplicates.


This is the unix shell:

Code:
[FONT=courier new]PAT=$1
PAT="`echo $PAT | sed -e 's/>/\\\>/g'`"
PAT="`echo $PAT | sed -e 's/|/\\\|/g'`"
PAT="`echo $PAT | sed -e 's/</\\\</g'`"
[/FONT]
[FONT=courier new]DIR=/dev/src/
FILENAME=/home/rzr/search.txt[/FONT]
[FONT=courier new]cd $DIR[/FONT]
[FONT=courier new]find . -type f -print 2>/dev/null | xargs -n50 grep -i -n "$PAT" 2>/dev/null > $FILENAME[/FONT]
[FONT=courier new]${DLC}/_progres -b -p /home/rzr/search.p  -e 200 -D 80 -l 63 2>&1[/FONT]
[FONT=courier new]rm -f [FONT=Courier New]/home/rzr/search.txt[/FONT]
chmod 660 [FONT=Courier New]/home/rzr/search[/FONT].xls
mv /home/rzr/search.xls /u/home/$PAT.xls
[/FONT]

The above shell calls the below 4gl code (search.p):

Code:
[FONT=courier new]DEFINE STREAM sinput.[/FONT]
[FONT=courier new]
DEFINE VARIABLE ip_SearchString AS CHARACTER   NO-UNDO.
DEFINE VARIABLE MyDir           AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cProgName       AS CHARACTER   NO-UNDO.
DEFINE VARIABLE iTotalCnt       AS INTEGER     NO-UNDO.
DEFINE VARIABLE iUniqueCt       AS INTEGER     NO-UNDO.[/FONT]
[FONT=courier new]
DEFINE TEMP-TABLE UNIQUE_Prog
    FIELD t_ProgName AS CHARACTER
    FIELD t_Count    AS INTEGER
    .[/FONT]
[FONT=courier new]ASSIGN 
    ip_SearchString = 'search'
    MyDir           = '/home/rzr/' + ip_SearchString .
[/FONT]
[FONT=courier new]INPUT STREAM sinput FROM VALUE(MyDir + ".txt").
REPEAT:
    IMPORT STREAM sinput cProgName.
    
    IF cProgName BEGINS 'GREP' THEN NEXT.
    IF cProgName = '' OR cProgName = ? OR cProgName = '?' THEN NEXT.[/FONT]
[FONT=courier new]    ASSIGN 
        cProgName = ENTRY(1,TRIM(SUBSTR(cProgName,3)),':')
        iTotalCnt = iTotalCnt + 1.[/FONT]
[FONT=courier new]    FIND FIRST UNIQUE_Prog 
         WHERE UNIQUE_Prog.t_ProgName = cProgName NO-ERROR.
    IF NOT AVAIL UNIQUE_Prog THEN
    DO:
        CREATE UNIQUE_Prog.
        ASSIGN
            iUniqueCt              = iUniqueCt + 1
            UNIQUE_Prog.t_ProgName = cProgName
            UNIQUE_Prog.t_Count    = UNIQUE_Prog.t_Count + 1.
    END.
END.

INPUT STREAM sinput CLOSE.[/FONT]
[FONT=courier new]
OUTPUT TO VALUE(MyDir + ".xls").
FOR EACH UNIQUE_Prog:
    EXPORT UNIQUE_Prog.t_ProgName.
END.[/FONT]

Feel free to play around with the above script / program and modify it as per your needs.
 
Thanks much rzr. With the help of your code/logic you have provided, I was able to get the data. But I do have one more question, hope you could share with me your ideas.

Ex. I want to retrieve the exact string with special character (the value that uses single or double quote) in each lines of the programs (ex. 'opsys' and or "opsys"). And will disregard the same word if there's no single quote or double quote base on my value string (w/character) search. With this I can determine the lines that uses the value with single or double quote in every programs (.p/.t).

Thanks.
 
okay - can i know why you would want to search for a string using single / double quotes? i thought *finding* the *string* was the business case scenario...
 
Because, I just noticed that whether my search string value IS USING single/double quote, still same line nos. in a program were captured. The singe/double quote in a name (string value) was disregard and it's just retrieving only the word (name).
 
I don't have access to unix terminal now and it's been a while since i last used unix. But can you try the search with `"string"` or `'string'` ?
 
Back
Top