Sponsored Content
Top Forums Shell Programming and Scripting sum using awk with pattern match Post 302694465 by sol_nov on Thursday 30th of August 2012 06:09:15 PM
Old 08-30-2012
CPU & Memory sum using awk with pattern match

I have a file which has data like this
Code:
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Insert completed. 5 rows added.
 *** Query completed. No rows found.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. No rows found.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. No rows found.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Insert completed. 10 rows added.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. No rows found.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. No rows found.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. No rows found.
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. One row found. 
 *** Query completed. No rows found.
 *** Query completed. One row found.

I want to sum all the rows found i.e. The total sum should be 47.

For now I am using

Code:
 awk '/\*\*\* Insert completed. | \*\*\* Query completed./ { SUM += $4 } END { printf ("Rows inserted: %d \n", SUM) }' file

But with this, it is skipping the 'One'. I am trying to equate One to 1. Please let me know how we can do this?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how do i pattern match a field with awk?

hi, let's say $numbers = "324 350 587" an so on... what i'm trying to do is this: awk -v numbers="$numbers" '{if (numbers ~ /$2/) print $0, "bla bla"}' file # file looks like this: 214 ..... 215 ... 216 .... 250 ... 324 325 ... 350 something ... ... 587 ... (4 Replies)
Discussion started by: someone123
4 Replies

2. Shell Programming and Scripting

want to pattern match using awk

Hello Friends, My script gives an output like below:- but i only want the red part to be displayed. how to i do that. I am enclosing my shell script after that. id='CCRCWebServerINSTALLDIR' id='AdministrationTools-CINSTALLDIR' id='AdministrationTools-ent-CINSTALLDIR'... (3 Replies)
Discussion started by: asirohi
3 Replies

3. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies

4. Shell Programming and Scripting

awk to sum specific field when pattern matches

Trying to sum field #6 when field #2 matches string as follows: Input data: 2010-09-18-20.24.44.206117 UOWEXEC db2bp DB2XYZ hostname 1 2010-09-18-20.24.44.206117 UOWWAIT db2bp DB2XYZ hostname ... (3 Replies)
Discussion started by: ux4me
3 Replies

5. Shell Programming and Scripting

pattern match .com in awk script

guys ! I want to search .com,.html files ..... how do I match pattern...? here's wht I hv written if ( $i ~ /.com/ ) even escaping it doesn't help if ( $i ~ /\.com/ ) (2 Replies)
Discussion started by: shreeprabha
2 Replies

6. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

7. 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

8. Shell Programming and Scripting

Why sum of recs in awk don't match total rec count?

I'm using awk to determine if a field starting in position 604 for length of 10 is not equal to ALL spaces. It's searching several files which are in the current directory. The below awk indicates that there are 84 records on all files where this field IS NOT equal to ALL spaces ( there are 10... (2 Replies)
Discussion started by: mjf
2 Replies

9. Shell Programming and Scripting

Pattern match with awk/sed - help

I need to grep for the pattern text inside the square brackets which are in red and not in green..my current code greps patterns both of them, which i don't want Input fileref|XP_002371341.1| oxoacyl-ACP reductase, putative gb|EPT24759.1| 3-ketoacyl-(acyl-carrier-protein) reductase ... (2 Replies)
Discussion started by: selvankj
2 Replies

10. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies
MSSQL_DATA_SEEK(3)														MSSQL_DATA_SEEK(3)

mssql_data_seek - Moves internal row pointer

SYNOPSIS
bool mssql_data_seek (resource $result_identifier, int $row_number) DESCRIPTION
mssql_data_seek(3) moves the internal row pointer of the MS SQL result associated with the specified result identifier to point to the specified row number, first row being number 0. The next call to mssql_fetch_row(3) would return that row. PARAMETERS
o $result_identifier - The result resource that is being evaluated. o $row_number - The desired row number of the new result pointer. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 mssql_data_seek(3) example <?php // Connect to MSSQL and select the database $link = mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php', $link); // Select all people $result = mssql_query('SELECT [name], [age] FROM [persons] WHERE [age] >= 13'); if (!$result) { die('Query failed.'); } // Select every 4th student in the results for ($i = mssql_num_rows($result) - 1; $i % 4; $i++) { if (!mssql_data_seek($result, $i)) { continue; } // Fetch the row ... } // Free the query result mssql_free_result($result); ?> PHP Documentation Group MSSQL_DATA_SEEK(3)
All times are GMT -4. The time now is 09:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy