Sponsored Content
Top Forums Shell Programming and Scripting awk print matching records and occurences of each record Post 302924422 by Don Cragun on Sunday 9th of November 2014 02:23:46 PM
Old 11-09-2014
Quote:
Originally Posted by iori
yes, that kind of outpur I am trying to get. Unfortunately the script you post doesn't print the output you said . Not sure why . I did change the order of the input files since with itu1.txt as first file I get no output and with

Code:
...some code here ..

}' dblp.xml itu1.txt

I get the following output:
--------------------------
Code:
1       Jakob  Bardram
1       Dominik  Grondziowski
1       Tijs  Slaats
1       Troels Bjerre S▒rensen
1       Florian  Berger
1       Rikke  Koch
1       Anker Helms J▒rgensen

Not sure what I am doing wrong. I am run the script under Ubuntu and Unix shell under windows as well . same results.

Thanks for your quick reply Smilie
I didn't just type in the results I expected my code to produce. The output I showed you was the actual output produced when I ran the code I showed you with the input files I showed you. It was run using ksh on a MacBook Pro running OS X Yosemite.

Were your input files created on your Windows system? The script I gave you will not work if:
  1. you reverse the order of the input files given as operands,
  2. the line terminators in your input files are the Windows two character carriage-return newline sequence instead of the single character UNIX system newline character,
  3. your dblp.xml file has more than one pair of XML tags per line,
  4. there are extraneous spaces in the names in the tags in the dblp.xml file or anywhere in the itu1.txt file , or
  5. if you put ANY carriage-return characters in the awk script I provided.
Note that every name in the itu1.txt file you used to get the output you showed us above contains two spaces between the first and last names when no middle name is provided. If the names in the dblp.xml file do not match exactly, they will not be counted.

If your input files are in Windows format (instead of Linux and UNIX system format), you can add the code shown in red below to convert the input files to the proper format:
Code:
awk -F '</?author>|</?editor>|</?publisher>|</?coauthor>|</?illustrator>' '
{	gsub("\r", "")
}
FNR == NR {
	faculty[$1]
	next
}
$2 in faculty {
	count[$0]++
}
END {	for(i in count)
		printf("%d\t%s\n", count[i], i)
}' itu1.txt dblp.xml

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk scripting - matching records and summing up time

Hello. I just found out about awk, and it appears that this could handle the problem I'm having right now. I first stumbled on the thread How to extract first and last line of different record from a file, and that problem is almost similar to mine. In my case, an ASCII file will contain the... (0 Replies)
Discussion started by: Gonik
0 Replies

2. Shell Programming and Scripting

Print all the fields of record using awk

Hi, i want to generate print statement using awk. i have 20+ and 30+ fields in each line Now its priting only first eight fields print statement as output not all. my record is as shown below filename ... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

3. Shell Programming and Scripting

AWK exclude first and last record, sort and print

Hi everyone, I've really searched for a solution to this and this is what I found so far: I need to sort a command output (here represented as a "cat file" command) and from the second down to the second-last line based on the second row and then print ALL the output with the specified section... (7 Replies)
Discussion started by: dentex
7 Replies

4. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

5. Shell Programming and Scripting

AWK print initial record and double

I have an initial record 0.018 I would like a script that would for i=0;i<200;i++ print 0.018*1 0.018*2 0.018*3 0.018*4 ... 0.018*200 using newline. (7 Replies)
Discussion started by: chrisjorg
7 Replies

6. UNIX for Dummies Questions & Answers

keeping last record among group of records with common fields (awk)

input: ref.1;rack.1;1 #group1 ref.1;rack.1;2 #group1 ref.1;rack.2;1 #group2 ref.2;rack.3;1 #group3 ref.2;rack.3;2 #group3 ref.2;rack.3;3 #group3 Among records from same group (i.e. with same 1st and 2nd field - separated by ";"), I would need to keep the last record... (5 Replies)
Discussion started by: beca123456
5 Replies

7. Shell Programming and Scripting

awk pattern matching name in records

Hi, I'm very new to these forums. I was wondering if someone could help an AWK beginner with a pattern matching an actor to his appearance in movies, which would be stored as records. Let's say we have a database of 4 movies (each movie a record with name, studio + year, and actor fields with... (2 Replies)
Discussion started by: Jill Ceke
2 Replies

8. Shell Programming and Scripting

Modifying text file records, find data in one place in the record and print it elsewhere

Hello, I have some text data that is in the form of multi-line records. Each record ends with the string $$$$ and the next record starts on the next line. RDKit 2D 15 14 0 0 0 0 0 0 0 0999 V2000 5.4596 2.1267 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 ... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

9. Shell Programming and Scripting

awk record matching

ok. so i have a list of country names which have been abbreviated. we'll call this list A i have another list that which contains the what country each abbreviated name means. we'll call this list B. so example of the content of list B: #delimited by tabs #ABBR COUNTRY COUNTRY... (2 Replies)
Discussion started by: SkySmart
2 Replies

10. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies
All times are GMT -4. The time now is 08:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy