Sponsored Content
Top Forums Shell Programming and Scripting awk: matching and not matching Post 302573575 by maverick72 on Tuesday 15th of November 2011 03:45:32 AM
Old 11-15-2011
Thank your both for the code.... i took agama's code and tried to add some of my own to grab the options (the -p or -b) but i'm surely missing something.

Code:
NF < 2 { host = $1; next; } 

NR == FNR {             
        prd_option[ prod[$8] = host ] = $9;
        next;
}

{                       
        bck_option[ back[$8] = host ] = $9;
        next;
}

    END {
        for( x in prod )
            printf( "%s, %s, %s, %s, %s\n", x, prod[x], prd_option[x], back[x] == "" ? "NO BACKUP HOST" : back[x], bck_option[x] );
}

In first loop: since x in prod = instance_name1, my toughts where that prd_option[instance_name1] would equal -p
In last printf: again since i have two arrays (one prod, one backup) i would get something in prd_option[instance_name1] that would equal my -p or -b or nothing if its empty.

I'm surely missing something OR i got this all wrong.... Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK pattern matching, first and last

In a nutshell, I need to work out how to return the last matching pattern from an awk //,// search. I can bring back the first, but am unsure how to obtain the last, and a simple tail won't work as the match could be over multiple lines. Secondly I would like some way of pattern matching, a... (10 Replies)
Discussion started by: smb_uk
10 Replies

2. Shell Programming and Scripting

pattern matching using awk.

Dear Team, How do we match two patterns on the same line using awk?Are there any logical operators which i could use in awk like awk '\gokul && chennai\' <filename> Eg: Input file: gokul,10/11/1986,coimbatore. gokul,10/11/1986,bangalore. gokul,12/04/2008,chennai.... (2 Replies)
Discussion started by: gokulj
2 Replies

3. UNIX for Dummies Questions & Answers

awk - pattern matching?

Hello all, I am trying to sort thru a database and print all the customers whose first names are only four characters. I just want to pull the first name only from the database. the database records appear like this in file: Mike Harrington:(510) 548-1278:250:100:175; first is name Mike... (4 Replies)
Discussion started by: citizencro
4 Replies

4. Shell Programming and Scripting

AWK help, matching 2 files into one

I'm newbie with AWK. What I'm trying to do is matching file1 and file2 into a file3 with records listed in columns with pipe as delimiter. The thing is the file1 has thousands of records while file2 has very few. But I want the file3 to show all records in file1 and with data from file2 to be... (2 Replies)
Discussion started by: jmeasel7
2 Replies

5. Shell Programming and Scripting

awk multiline matching

I have a file that looks something like this with lots of text before and after. Distance method: Sum of squared size difference (RST) </data> <pairwiseDifferenceMatrix time="02/08/11 at 13:08:27"> 1 2 1 448.82151 507.94231 2 ... (7 Replies)
Discussion started by: mgray
7 Replies

6. Shell Programming and Scripting

String matching using awk

Hello, I am working with google ngram data set which is of size 100s of gb. Before using it with Java, I wanted to filter it out using shell script. Here is a sample line in the file: 2.55 1.57 1992 10 20 30 The first two fields (2.55 and 1.57) are... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

7. Shell Programming and Scripting

Matching two files with awk

Hello, I have two files as follow: AFFY_ID RS_ID CHROMOSOME POS_START POS_END ALLELE1 ALLELE2 SNP_A-1780283 rs17011450 chr4 127630275 127630276 C T SNP_A-1780285 rs6919430 chr6 90919464 90919465 A C SNP_A-1780286 --- chr7 104281409 104281410 A G SNP_A-1780301 rs2342723 chr16 5748790... (1 Reply)
Discussion started by: Homa
1 Replies

8. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

9. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

10. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies
math(n) 							 Tcl Math Library							   math(n)

NAME
math - Tcl Math Library SYNOPSIS
package require Tcl 8.2 package require math ?1.2? ::math::cov value value ?value ...? ::math::integrate list of xy value pairs ::math::fibonacci n ::math::max value ?value ...? ::math::mean value ?value ...? ::math::min value ?value ...? ::math::prod value ?value ...? ::math::random ?value1? ?value2? ::math::sigma value value ?value ...? ::math::stats value value ?value ...? ::math::sum value ?value ...? DESCRIPTION
The math package provides utility math functions. COMMANDS
::math::cov value value ?value ...? Return the coefficient of variation expressed as percent of two or more numeric values. ::math::integrate list of xy value pairs Return the area under a "curve" defined by a set of x,y pairs and the error bound as a list. ::math::fibonacci n Return the n'th Fibonacci number. ::math::max value ?value ...? Return the maximum of one or more numeric values. ::math::mean value ?value ...? Return the mean, or "average" of one or more numeric values. ::math::min value ?value ...? Return the minimum of one or more numeric values. ::math::prod value ?value ...? Return the product of one or more numeric values. ::math::random ?value1? ?value2? Return a random number. If no arguments are given, the number is a floating point value between 0 and 1. If one argument is given, the number is an integer value between 0 and value1. If two arguments are given, the number is an integer value between value1 and value2. ::math::sigma value value ?value ...? Return the population standard deviation of two or more numeric values. ::math::stats value value ?value ...? Return the mean, standard deviation, and coefficient of variation as percent as a list. ::math::sum value ?value ...? Return the sum of one or more numeric values. KEYWORDS
math, statistics math 4.2 math(n)
All times are GMT -4. The time now is 06:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy