查找文件集AWK / bash中的最大/最小值

时间:2022-05-12 20:13:30

I have about ~1000 data files in format of file_1000.txt, file_1100.txt, etc.

我有大约1000个数据文件,格式为file_1000.txt,file_1100.txt等。

Each of this file contains data in 2 columns and more than 2k rows (this is an example):

每个文件包含2列和2k行以上的数据(这是一个例子):

1.270000e-01 1.003580e+00
6.270000e-01 1.003582e+00
1.126000e+00 1.003582e+00
1.626000e+00 1.003584e+00
2.125000e+00 1.003584e+00
2.625000e+00 1.003586e+00
...

I want to find maximum value in each data file from 2nd column and store these numbers anywhere (particulary, plot in gnuplot). I tried to use the script:

我想在第二列的每个数据文件中找到最大值,并将这些数字存储在任何地方(特别是,在gnuplot中绘图)。我试着使用脚本:

cat file_1*00.txt | awk '{if ($2 > max) max=$2}END{print max}'

But it searches all files with file_1*00.txt condition and outputs only 1 number - maximum value from all these files.

但它会搜索所有带有file_1 * 00.txt条件的文件,并只输出1个数字 - 所有这些文件的最大值。

How can I change the script to output maximums from ALL the files I mentioned in scrypt?

如何更改脚本以从我在scrypt中提到的所有文件输出最大值?

Thanks!

谢谢!

1 个解决方案

#1


2  

awk '{if(a[FILENAME]<$2)a[FILENAME]=$2}END{for(i in a)print i,a[i]}' file_1*00.txt 

each file max ?

每个文件最大?

#1


2  

awk '{if(a[FILENAME]<$2)a[FILENAME]=$2}END{for(i in a)print i,a[i]}' file_1*00.txt 

each file max ?

每个文件最大?