Sponsored Content
Top Forums Shell Programming and Scripting awk pattern match and search in single statement Post 302428586 by Bruble on Thursday 10th of June 2010 09:58:25 AM
Old 06-10-2010
Java awk pattern match and search in single statement

Hi All,
I am trying to alter all lines between EXEC SQL and END-EXEC that have an INCLUDE in them.

The following code
Code:
search="INCLUDE "
  cp -f ${WORK}/$file.in ${WORK}/$file.wrk2
  for item in `echo $search `; do
      >  ${WORK}/$file.wrk1
      awk  -vITEM="$item" '{
          if ( $0 ~ ITEM ) {
             savetext = substr($0,1,80);
             col7 = substr($0,7,1);
             print "MIGAU1" col7 "       BEGIN DECLARE SECTION"
             print "MIGAU1" col7 "    END-EXEC."
             print "MIGAU1" col7 "    EXEC SQL"
             print savetext
             print "MIGAU1" col7 "    END-EXEC."
             print "MIGAU1" col7 "    EXEC SQL"
             print "MIGAU1" col7 "       END DECLARE SECTION"
             }
         else { print $0 }
      }' ${WORK}/$file.wrk2 >> ${WORK}/$file.wrk1

works to alter the lines containing include but now I want to include the following pattern matching
Code:
awk '/EXEC SQL/,/END-EXEC/' filein

I have tried
Code:
search="INCLUDE "
  cp -f ${WORK}/$file.in ${WORK}/$file.wrk2
  for item in `echo $search `; do
      >  ${WORK}/$file.wrk1
      awk  '/EXEC SQL/,/END-EXEC/' || -vITEM="$item" '{
          if ( $0 ~ ITEM ) {
             savetext = substr($0,1,80);
             col7 = substr($0,7,1);
             print "MIGAU1" col7 "       BEGIN DECLARE SECTION"
             print "MIGAU1" col7 "    END-EXEC."
             print "MIGAU1" col7 "    EXEC SQL"
             print savetext
             print "MIGAU1" col7 "    END-EXEC."
             print "MIGAU1" col7 "    EXEC SQL"
             print "MIGAU1" col7 "       END DECLARE SECTION"
             }
         else { print $0 }
      }' ${WORK}/$file.wrk2 >> ${WORK}/$file.wrk1

and various other things but the script just hangs when I do this.

Any help appreciated.
 

10 More Discussions You Might Find Interesting

1. IP Networking

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (1 Reply)
Discussion started by: olapxpert
1 Replies

2. UNIX for Dummies Questions & Answers

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (7 Replies)
Discussion started by: olapxpert
7 Replies

3. Shell Programming and Scripting

search files which doesnot match pattern ?

Hi I need a command to search files in a directory which does not match with pattern .. Plz send me this Ex : Test is directory and has some 10 files with different name all are with *.dat extension , need to search files which doesnot contain word "Dummy file". Thanks (6 Replies)
Discussion started by: madankumar
6 Replies

4. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

5. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

6. Shell Programming and Scripting

How to specify more then one pattern in a single mget statement of ftp command?

hi, i am using ftp command to get some files from a remote server. if the remote server contains files of different extension. abc.txt def.txt ghi.lst jkl.cnf is it possible to get all the three type of files in one ftp? i am using this ftp command $FTP $Remote_server <<_FTP1 ... (4 Replies)
Discussion started by: Little
4 Replies

7. Shell Programming and Scripting

Search Pattern and combine into single file

Hi Experts Please help me out with the following thing: 2 files and want the output file: {No for using FOR loop because I got 22 million lines} Tried that "It processes only 8000 records per hour" I need a faster way out !!! FileA: 9051 9052 9053 9054 9055 9056 9057 9058 9059 ... (5 Replies)
Discussion started by: navkanwal
5 Replies

8. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

9. Shell Programming and Scripting

awk pattern match by looping through search patterns

Hi I am using Solaris 5.10 & ksh Wanted to loop through a pattern file by reading it and passing it to the awk to match that value present in column 1 of rawdata.txt , if so print column 1 & 2 in to Avlblpatterns.txt. Using the following code but it seems some mistakes and it is running for... (2 Replies)
Discussion started by: ananan
2 Replies

10. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies
PDO.EXEC(3)								 1							       PDO.EXEC(3)

PDO
::exec - Execute an SQL statement and return the number of affected rows SYNOPSIS
public int PDO::exec (string $statement) DESCRIPTION
PDO.exec(3) executes an SQL statement in a single function call, returning the number of rows affected by the statement. PDO.exec(3) does not return results from a SELECT statement. For a SELECT statement that you only need to issue once during your program, consider issuing PDO.query(3). For a statement that you need to issue multiple times, prepare a PDOStatement object with PDO.prepare(3) and issue the statement with PDOStatement.execute(3). PARAMETERS
o $statement - The SQL statement to prepare and execute. Data inside the query should be properly escaped. RETURN VALUES
PDO.exec(3) returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, PDO.exec(3) returns 0. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. The following example incorrectly relies on the return value of PDO.exec(3), wherein a statement that affected 0 rows results in a call to die(3): <?php $db->exec() or die(print_r($db->errorInfo(), true)); ?> EXAMPLES
Example #1 Issuing a DELETE statement Count the number of rows deleted by a DELETE statement with no WHERE clause. <?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); /* Delete all rows from the FRUIT table */ $count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'"); /* Return number of rows that were deleted */ print("Deleted $count rows. "); ?> The above example will output: Deleted 1 rows. SEE ALSO
PDO.prepare(3), PDO.query(3), PDOStatement.execute(3). PHP Documentation Group PDO.EXEC(3)
All times are GMT -4. The time now is 10:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy