Match look up file and find result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match look up file and find result
# 8  
Old 09-10-2012
The way I understand what was desired, the text in the last field ("Approved", "Discontinued", "Phase II", etc.) should appear in the output files rather than putting "Approved" in that spot no matter what the status is.

First a few notes:
  1. The entries you specified for lookupfile contain the string "HT" twice. I assume either that there are only seven different disease codes, or that one of the "HT" entries is a typo that needs to be corrected.
  2. The text of mainfile given in the 1st message in this thread has spaces between fields rather than tab characters. To make things work correctly with fields that contain spaces, the input field separators have to be something other than spaces. Given that the script supplied in that message used -F'\t', I replaced all sequences of multiple adjacent space characters with a single tab character and wrote the results to a file named mainfile2 and am using that as the 2nd input file rather than the original mainfile given.
  3. There are several entries in mainfile that end with "CAD,CD,CD". The entries will produce two lines of output in file_CD.txt for every input line that contains an occurrence of this string.
  4. The version of awk I'm using (from Mac OS X Lion) will not accept a concatenation of strings when specifying an output file. I think this is a bug in OS X's awk utility, but I don't know how common this restriction is. Therefore, the script below computes the name of the output file before using it in the print statement.
I believe the awk script below will do what was wanted:
Code:
awk -F'\t' 'FNR==NR {a[$0]
	next
}
 {	m = split($6, c, " ")
	n = split(c[m], b, ",")
	$6 = substr($6, 1, length($6) - length(c[m]) - 1)
	for(i = 1; i <= n; i++)
		if(b[i] in a) {
			file = "file_"b[i]".txt"
			print > file
		}
}' OFS='\t' lookupfile mainfile2

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find particular file-name in file and get result in table in mail?

We have 100 linux servers, All send logs to both centralize server(server1 and serverb). all send logs every day and stores in /syslog folder with hostname.log file. I need to prepare script to check every day from both centralize server(server1 and serverb) and send mail in table format. ... (1 Reply)
Discussion started by: yash_message
1 Replies

2. UNIX for Beginners Questions & Answers

Match file and find count

Hi All, I have transaction in one file.I want to match that to another file and find the number of time the transaction is available on the other file.I need to take each record from TRANSFILE and match that with SPEND FILE and find the number of counts of the transaction TRANSFILE: ... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

3. Shell Programming and Scripting

awk parse result that match data from file

i run command that return this result,example : gigabitethernet2/2/4:NotPresent, gigabitethernet2/1/17:UP, gigabitethernet2/1/10:UP, gigabitethernet2/1/5:UP, gigabitethernet2/1/9:UP, gigabitethernet2/1/36:DOWN, gigabitethernet2/1/33:DOWN, gigabitethernet2/1/8:UP,... (19 Replies)
Discussion started by: wanttolearn1
19 Replies

4. Shell Programming and Scripting

Compare two files and find match and print the header of the second file

Hi, I have two input files; file1 and file2. I compare them based on matched values in 1 column and print selected columns of the second file (file2). I got the result but the header was not printed. i want the header of file2 to be printed together with the result. Then i did below codes:- ... (3 Replies)
Discussion started by: redse171
3 Replies

5. Shell Programming and Scripting

Find diff bet 2 files and store result in another file

Hi I want to compare 2 files. The files have the same amount of rows and columns. So each line must be compare against the other and if one differs from the other, the result of both must be stored in a seperate file. I am doing this in awk. Here is my file1: Blocks... (2 Replies)
Discussion started by: ladyAnne
2 Replies

6. UNIX Desktop Questions & Answers

find result

When searching for some files which match some specific criteria with find from the root directory, I got a listing of a bunch of files that say "Permission Denied". How can do my search and not show the files that I don't have the permission to list? Thanks, (3 Replies)
Discussion started by: Pouchie1
3 Replies

7. Shell Programming and Scripting

How to find first match and last match in a file

Hi All, I have a below file: ================== 02:53 pravin-root 02:53 pravin-root 03:05 pravin-root 02:55 pravin1-root 02:59 pravin1-root ================== How do I find the first and last value of column 1. For example, how do I find 02:53 is the first time stamp and 03:05 is... (3 Replies)
Discussion started by: praving5
3 Replies

8. Shell Programming and Scripting

Find match in two diff file - local srv and remote server

Perl Guru.... I need to compare two diff file (file1.abc will locate in current server and file2.abc will locate in remote server), basically the script will look for match in both file and only will send out email if there is no match and also give me list of unmatch and dups as well. So... (0 Replies)
Discussion started by: amir07
0 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

result of find

Hey, I am using 'find' to check the existence of a file which is created today, and this is what I have find . -name $filename -mtime +0 -exec ls {} \; my problem is I need to know what the above command actually get anything, so can anyone give me some pointer on how to do... (1 Reply)
Discussion started by: mpang_
1 Replies
Login or Register to Ask a Question