Sponsored Content
Top Forums Shell Programming and Scripting Optimizing for loop with awk or anything similar and portable Post 302978163 by SkySmart on Wednesday 27th of July 2016 02:37:10 AM
Old 07-27-2016
Optimizing for loop with awk or anything similar and portable

The variable COUNTPRO contains:

Code:
COUNTPRO='Error__posting__message__to__EMR__Queue=0
Error__parsing__ReceiptSummary=0
xinetd__=4327
HTTP__1_1__500___=0
START__=2164
Marshaller__exception__while__converting__to__Receipt__xml=0
MessagePublisher__is__not__configured__correctly=0
Error__populating__JAXB__Object=0
collectd__=42'

The variable STRING1 contains:

Code:
STRING1='Error.*posting.*message.*to.*EMR.*Queue#1,1#_P_Marshaller.*exception.*while.*converting.*to.*Receipt.*xml#1,1#_P_Error.*parsing.*ReceiptSummary#1,1#_P_Error.*populating.*JAXB.*Object#1,1#_P_MessagePublisher.*is.*not.*configured.*correctly#1,1#_P_HTTP.*1.1.*500.*-#1,1#_P_xinetd.*#1,1#_P_START:*#1,1#_P_collectd.*#1,1#'

my code:

Code:
 
for allcounts in $(echo $COUNTPRO | sed 's~,~ ~g')
do
      for estr in $(echo ${STRING1} | sed 's~|~ ~g')
      do
                WARNING=$(echo ${estr} | awk -F"[#,]" '{print $2}')
                CRITICAL=$(echo ${estr} | awk -F"[#,]" '{print $3}')
                samestring=$(echo ${estr} | sed 's_#[^#]*#__g' | sed 's/[^=0-9a-zA-Z]/_/g' | sed 's/__/_/g')

                newstring=$(echo ${allcounts} | awk -F"=" '{print $1}' | sed 's~__~_~g')

                if [ "${samestring}" = "${newstring}" ] ; then
                        VALEACH=$(echo ${allcounts} | awk -F"=" '{print $NF}' | sed 's~_n$~~g')
                         if [ $VALEACH -lt $WARNING ] ; then
                                       echo "OK-LGRBT:$allcounts"
                                       break
                        elif [ $VALEACH -ge $WARNING ] && [ $VALEACH -lt $CRITICAL ] ; then
                                      echo "WARNING-LGRBT:$allcounts"
                                      break
                        elif [ $VALEACH -ge $CRITICAL ] ; then
                                     echo "CRITICAL-LGRBT:$allcounts"
                                     break
                       fi
              fi
      done
done


Last edited by SkySmart; 07-27-2016 at 03:43 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to get the similar function in while loop or for loop

Dear all How to write the shell script for the following statement: (C programming) for (i=0;i<30;i++) { if i=1 continue *skip this number (To do function here....) ... } similar statement in while loop.... I wrote the script in sh... (3 Replies)
Discussion started by: trynew
3 Replies

2. Shell Programming and Scripting

awk - Counting number of similar lines

Hi All I have the input file OMAK_11. OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE ... (8 Replies)
Discussion started by: dhanamurthy
8 Replies

3. Shell Programming and Scripting

awk, sed or similar log repair help

I have a log file that for some reason, once or two time a month, line foods are missing. This log is generated from vmstat everyminute. I dont know why sometimes it does this. Each line in the log should have 18 columns separated by one or more spaces. Good Log: (not actual log) 1 1... (8 Replies)
Discussion started by: Ikon
8 Replies

4. Shell Programming and Scripting

Help in grep function or similar using awk

I have a list of id; for example: file 1 dfghd dfghe dfgey dfgeu I have another data file that contain this ids as headers; for ex. file2 >dfghd gfdgfddl;klfkld;ld;lgl;dld'l'dv >dfghe gkwhjhsgdjdjdjhjddj >dfgey jdkjfhdjhfdkjhfdkhkdk I wanted to compare file 1 and file 2... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

5. Shell Programming and Scripting

Help with awk or something similar

i have a file like this: wedd01A1 1 wedd01A2 2 wedd01A3 1 wedd02A2 3 wedd02A3 4 wadd02A1 1 wadd02A2 5 wqdd01A1 3 wsdd01A3 1 i want out like this: A1 A2 A3 wedd01 1 2 1 wedd02 0 3 4 wadd02 1 5 0 wqdd01 3 0 0 wsdd01 0 0 1 (8 Replies)
Discussion started by: aydj
8 Replies

6. Shell Programming and Scripting

Merging two columns from two files with similar names into a loop

I have two files like this: fileA.net A B C fileA.dat 1 2 3 and I want the output output_expected A 1 B 2 C 3 I know that the easier way is to do a paste fileA.net fileA.dat, but the problem is that I have 10,000 couple of files (fileB.net with fileB.dat; fileC.net with... (3 Replies)
Discussion started by: valente
3 Replies

7. Shell Programming and Scripting

Optimizing awk script

Can this awk statement be optimized? i ask because log.txt is a giant file with several hundred thousands of lines of records. myscript.sh: while read line do searchterm="${1}" datecurr=$(date +%s) file=$(awk 'BEGIN{split(ARGV,var,",");print var}' $line) ... (3 Replies)
Discussion started by: SkySmart
3 Replies

8. Shell Programming and Scripting

Add values of similar patterns with awk

so my output is this: session_closed=157 session_opened=151 session_closed=18 session_opened=17 there are two patterns here, but with different values. the two patterns are "session_opened" and "session_closed". i expect there will be many more other patterns. what i want to do is... (8 Replies)
Discussion started by: SkySmart
8 Replies

9. Shell Programming and Scripting

Vlookup using awk non similar files

I need to vlookup and check the server not found. Source file 1 server1 server2 server3 server4 server5_root server6_silver server7 server7-test server7-temp Source file 2 server1_bronze (6 Replies)
Discussion started by: ranjancom2000
6 Replies

10. Shell Programming and Scripting

Optimizing bash loop

now, i have to search for a pattern within a particular time frame which the user will provide in the following format: 19/Jun/2018:07:04,21/Jun/2018:21:30 it is easy to get tempted to attempt this search with a variation of the following awk command: awk... (3 Replies)
Discussion started by: SkySmart
3 Replies
MSSQL_NUM_FIELDS(3)													       MSSQL_NUM_FIELDS(3)

mssql_num_fields - Gets the number of fields in result

SYNOPSIS
int mssql_num_fields (resource $result) DESCRIPTION
mssql_num_fields(3) returns the number of fields in a result set. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns the number of fields, as an integer. EXAMPLES
Example #1 mssql_num_fields(3) example <?php // Connect to MSSQL and select the database $link = mssql_connect('KALLESPCSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php', $link); // Select some data from our database $data = mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]'); // Construct a table echo '<table border="1">'; $header = false; // Iterate through returned results while ($row = mssql_fetch_array($data)) { // Build the table header if (!$header) { echo '<thead>'; echo '<tr>'; for ($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i) { echo '<td>' . ucfirst($row[$i]) . '</td>'; } echo '</tr>'; echo '</thead>'; echo '<tbody>'; $header = true; } // Build the row echo '<tr>'; foreach($row as $value) { echo '<td>' . $value . '</td>'; } echo '</tr>'; } // Close table echo '</tbody>'; echo '</table>'; // Clean up mssql_free_result($data); mssql_close($link); ?> SEE ALSO
mssql_query(3), mssql_fetch_field(3), mssql_num_rows(3). PHP Documentation Group MSSQL_NUM_FIELDS(3)
All times are GMT -4. The time now is 01:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy