Find and compare values from different txt files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and compare values from different txt files
# 1  
Old 12-06-2014
Find and compare values from different txt files

Hello, i am new in Bash. Actually i have a directory : /home/resultfiles and inside i have these txt files:
531_1.out.res, 531_2.out.res , 531_3.out.res
532_1.out.res, 532_2.out.res , 532_3.out.res
533_1.out.res, 533_2.out.res, 533_3.out.res
All these txt files has this format :
Code:
num_q  all       1
num_ret                    all    1000
num_rel all       48
num_rel_ret        all      33
map all       0.3144

My purpose is to make a script in order to find the maximum value for map(0.3144 in the example) between 531_1.out.res, 531_2.out.res , 531_3.out.res, then the maximum value between 532_1.out.res, 532_2.out.res , 532_3.out.res, and then the maximum value between 533_1.out.res, 533_2.out.res, 533_3.out.res. When i find the maximum value for them (531,532,533) i want to return also the name of the txt file where the maximum value map was found.
I suppose that i have to store firstly all the map values in an array and then find the maximum.
Thanks in advance!

Last edited by Don Cragun; 12-07-2014 at 12:26 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 12-07-2014
You could try something like:
Code:
awk '
function PrintPrev() {
	if(last != "")
		printf("Maximum value for set %s in file %s is %s\n",
			last, mf, mv)
}
$1 == "map" && $2 == "all" {
	x = index(FILENAME, "_")
	set = substr(FILENAME, 1, x - 1)
	if(set != last) {
		PrintPrev()
		last = set
		mf = FILENAME
		mv = $3
	} else if($3 > mv) {
		mf = FILENAME
		mv = $3
	}
}
END {	PrintPrev()
}' *.res

If you're using a Solaris/SunOS system, change awk to /usr/xpg4/bin/awi, /usr/xpg6/bin/awk, or nawk.
# 3  
Old 12-07-2014
Code:
$ grep '^map' *.res | sort -nk3,3 | awk -F'_' '{ A[$1]=$0 }END{ for (i in A) print A[i]}'
531_2.out.res:map all 0.4144
532_1.out.res:map all 0.9144
533_3.out.res:map all 1.8142
$

Since you didn't specify how the output should look like, the above might suffice.
# 4  
Old 12-07-2014
Thanks so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare values in two different files

Hello, I have output in one file that looks like: AA 3 BB 1 CC 3 DD 6 EE 2 FF 6 And output in another file that looks like: 1 EE 3 CC 2 AA I basically want to be able to match the counts in each file against the correct corresponding initials (and then obviosuly base a command on... (7 Replies)
Discussion started by: Nik44
7 Replies

2. Shell Programming and Scripting

How to get a variables from two different txt files and need to run a command using that values?

Hi Q1. I have a scenario to run cfsend command,this command will run based on node name,port num,userid and password I was created one file called test.txt and inserted two values,then called those two values from test.txt file that pointed to node place and ran the script it worked fine Now... (10 Replies)
Discussion started by: venuvaka
10 Replies

3. Shell Programming and Scripting

Compare two txt files,mismatches will be in new txt files

Hi, Below are the sample data for txt files. txt file 1 Partnumber|catgroup_id 10001082|46016 10001093|4680 10001093|386003 10001093|463004 10003251|683 10003251|63005 10003252|463005 10003252|4683 10003260|463005 10003260|4683 10003264|4683 10003264|463005 13420000|67... (5 Replies)
Discussion started by: Ankita Talukdar
5 Replies

4. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

5. Shell Programming and Scripting

ksh to compare alphanumeric values from 2 files

Hi there, I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message. lspv_pre.out hdisk0 00c39eaa451144dd rootvg active hdisk1 00c39eaa45223322 ... (3 Replies)
Discussion started by: mbak
3 Replies

6. Shell Programming and Scripting

Compare to files and export only different values

Hello, I need to compare two files which have the following structure File1: No : 1 Name : George/Brown Value2 : type2 Value3 : type3 Date : Wed Oct 20 11:12:58 2010 Value : yes No : 2 Name : John/Cash Value2 :... (4 Replies)
Discussion started by: @dagio
4 Replies

7. Shell Programming and Scripting

Need to compare values on two CSV files

:( Hello, Having a problem with reading two files using awk/nawk, am new to both them. I need to compare field values between two csv files and arrange for an appropriate output if both the values are equal or not for each feild. $cat File1.csv... (4 Replies)
Discussion started by: pgop
4 Replies

8. Shell Programming and Scripting

Compare two txt files

Hi, I want to compare two txt files and output the matches to a file. For example I have FILE1 - accounts1.txt Peter norman elektra table CHAIR Newman nOvice FILE2 - accounts2.txt noland trainfil peter Newman norman neverlan CHAIR jackson KelSo (4 Replies)
Discussion started by: novice_sn6
4 Replies

9. Shell Programming and Scripting

Compare values between files

I have two files with same name residing in different directory. Each file has 14 columns. I want to compare column by column for each row. Also, have to take two columns as key identifier;pick a row in File1; retrieve the corresponding row from file2 and then compare the values. Can... (1 Reply)
Discussion started by: Sangtha
1 Replies

10. Shell Programming and Scripting

compare two txt files

i have two files file1 ----- absgsh jshsh shshhs hshhs file2 ------ kakkaka iurir brbrbrbr rjrbjrhjkehr rgjhergrhg hrghrgh jrhgrjg i want bash shell script to campare line1-file1 - line-file2 line2-file1 -line2 file2 ........ ( without diff , cmp , comm ) thanks... (8 Replies)
Discussion started by: space13
8 Replies
Login or Register to Ask a Question