Sponsored Content
Top Forums Shell Programming and Scripting awk: matching and not matching Post 302572953 by binlib on Friday 11th of November 2011 10:28:14 PM
Old 11-11-2011
Your code doesn't seem to do what you claimed. I guess you wanted something like the following. It doesn't print exactly the format you wanted, but should be easy to adapt.

Code:
$ cat list.awk
BEGIN {
  RS = ""
  FS = "\n"
}
{
  for (i = 2; i <= NF; i++) {
    split($i, a, " ")
    if (NR == FNR)
      h[a[8]] = $1
    else 
      print a[7], $1, a[8], (a[8] in h)? h[a[8]] : "NO"
  }
}
END { print "Done" }

$ awk -f list.awk file2 file1

Didn't realize that agama has answered, but nevertheless ...
This User Gave Thanks to binlib For This Post:
 

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
Tcl_StringMatch(3)					      Tcl Library Procedures						Tcl_StringMatch(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_StringMatch, Tcl_StringCaseMatch - test whether a string matches a pattern SYNOPSIS
#include <tcl.h> int Tcl_StringMatch(str, pattern) int Tcl_StringCaseMatch(str, pattern, flags) ARGUMENTS
const char *str (in) String to test. const char *pattern (in) Pattern to match against string. May contain special characters from the set *?[]. int flags (in) OR-ed combination of match flags, currently only TCL_MATCH_NOCASE. 0 specifies a case-sensitive search. _________________________________________________________________ DESCRIPTION
This utility procedure determines whether a string matches a given pattern. If it does, then Tcl_StringMatch returns 1. Otherwise Tcl_StringMatch returns 0. The algorithm used for matching is the same algorithm used in the string match Tcl command and is similar to the algorithm used by the C-shell for file name matching; see the Tcl manual entry for details. In Tcl_StringCaseMatch, the algorithm is the same, but you have the option to make the matching case-insensitive. If you choose this (by passing TCL_MATCH_NOCASE), then the string and pattern are essentially matched in the lower case. KEYWORDS
match, pattern, string Tcl 8.5 Tcl_StringMatch(3)
All times are GMT -4. The time now is 04:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy