Sponsored Content
Top Forums UNIX for Dummies Questions & Answers regex - display all occurrences of match Post 302287436 by danmauer on Friday 13th of February 2009 05:33:14 PM
Old 02-13-2009
regex - display all occurrences of match

i don't want to display the whole line but i want to display all the string(s) that match the Regex, even if their are more then one match per line in my file.

data:

mds_ar/bin/uedw92wp.ksh:cat $AI_SQL/wkly_inqry.sql $AI_SQL/wkly_inqry_trtry.sql $AI_SQL/wkly_nb_trtry.sql \
mds_ar/bin/uedw92wp.ksh:$AI_SQL/wkly_new_bsns.sql $AI_SQL/wkly_runstats.sql $AI_SQL/wkly_mqt.sql \
mds_ar/bin/uedw92wp.ksh:$AI_SQL/wkly_prtl_bnd.sql $AI_SQL/wkly_prtl_bnd_st.sql $AI_SQL/wkly_prtl_inqry.sql \
mds_ar/bin/uedw92wp.ksh:$AI_SQL/wkly_prtl_inqry_st.sql $AI_SQL/wkly_prtl_nb.sql $AI_SQL/wkly_prtl_nb_st.sql > $EDW_TMP/wkly.sql
mds_ar/bin/uedw92wp.ksh:cat $AI_SQL/mnthly_mqt.sql $AI_SQL/actl_pln.sql > $EDW_TMP/mthly.sql

the following code: only gives me the first match per line... i want to see each match from the same line too.

Code:
#!/usr/bin/nawk -f
# demonstrate the match function

BEGIN {
     regex="AI_SQL\/[a-zA-Z_]+\.sql"
}
{
    if (match($0,regex)) {
#           RSTART is where the pattern starts
#           RLENGTH is the length of the pattern
            before = substr($0,1,RSTART-1);
            pattern = substr($0,RSTART,RLENGTH);
            after = substr($0,RSTART+RLENGTH);
#            printf("%s\n<%s>\n%s\n", before, pattern, after);
           printf("<%s>\n", pattern);
    }
}


Last edited by danmauer; 02-13-2009 at 07:38 PM.. Reason: add more details
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regex to match basename

Hi Can somebody please help me know how do i match the basename using a regular expression using posix standard in shell script suppose i want to match /u01/Sybase/data/master.dbf the result should be master.dbf as i want to match everything after the last / regards (8 Replies)
Discussion started by: xiamin
8 Replies

2. UNIX for Advanced & Expert Users

Regex to match IP address

What do you think of this regex to match IP address? I have been reading up on regex and have seen some really long ones for IP. Would this fail in any scenarios? (+\.){3}* (5 Replies)
Discussion started by: glev2005
5 Replies

3. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

4. Shell Programming and Scripting

Regex find first 5-7 occurrences of a set of digits within a string

Using these strings as an example: <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=145148&amp;playTogether=True',960,540,943437);return false;" title=""> <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=1451486&amp;playTogether=True',960,540,94343);return false;" title=""> <a... (12 Replies)
Discussion started by: metallica1973
12 Replies

5. Shell Programming and Scripting

Only Regex pattern match help

Hi We have a tool to monitor logs in our environment. The tool accepts log pattern match only using regex and I accept I am a n00b in that:confused:. I had been banging my head to make it work without much success and at last had to turn on to my last option to post it here. I had got great... (2 Replies)
Discussion started by: radioactive9
2 Replies

6. Shell Programming and Scripting

Print occurrences for pattern match

Hi All, I want to print all the occurrences for a particular pattern from a file. The catch is that the pattern search is partial and if any word in the file contains the pattern, that complete word has to be printed. If there are multiple words matching the pattern on a specific line, then all... (2 Replies)
Discussion started by: decci_7
2 Replies

7. UNIX for Advanced & Expert Users

sed REGEX to print multiple occurrences of a pattern from a line

I have a line that I need to parse through and extract a pattern that occurs multiple times in it. Example line: getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed,... (4 Replies)
Discussion started by: Vidhyaprakash
4 Replies

8. Shell Programming and Scripting

Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

10. Shell Programming and Scripting

Count the number of string occurrences to display 0 entries in output

Hello Friends, Can somebody assist an issue I am having? I have a separate file with a list of account ids XXX200B02Y01 XXX200B03Y01 XXX200B05Y01 XXX200B07Y01 XXX200B08Y01 I call the file, and run an egrep against a directory and logfiles AccountID=$(cat... (2 Replies)
Discussion started by: liketheshell
2 Replies
FBSQL_CREATE_BLOB(3)							 1						      FBSQL_CREATE_BLOB(3)

fbsql_create_blob - Create a BLOB

SYNOPSIS
string fbsql_create_blob (string $blob_data, [resource $link_identifier]) DESCRIPTION
Creates a BLOB from the given data. PARAMETERS
o $blob_data - The BLOB data. o $ link_identifier -A FrontBase link identifier returned by fbsql_connect(3) or fbsql_pconnect(3).If optional and not specified, the function will try to find an open link to the FrontBase server and if no such link is found it will try to create one as if fbsql_connect(3) was called with no arguments. RETURN VALUES
Returns a resource handle to the newly created BLOB, which can be used with insert and update commands to store the BLOB in the database. EXAMPLES
Example #1 fbsql_create_blob(3) example <?php $link = fbsql_pconnect("localhost", "_SYSTEM", "secret") or die("Could not connect"); $filename = "blobfile.bin"; $fp = fopen($filename, "rb"); $blobdata = fread($fp, filesize($filename)); fclose($fp); $blobHandle = fbsql_create_blob($blobdata, $link); $sql = "INSERT INTO BLOB_TABLE (BLOB_COLUMN) VALUES ($blobHandle);"; $rs = fbsql_query($sql, $link); ?> SEE ALSO
fbsql_create_clob(3), fbsql_read_blob(3), fbsql_read_clob(3), fbsql_set_lob_mode(3). PHP Documentation Group FBSQL_CREATE_BLOB(3)
All times are GMT -4. The time now is 09:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy