首页 > 解决方案 > I have 3000 text files, with each reporting a time duration at the end. Is there a way in Bash to find what the maximum value was?

问题描述

I have 3000 text files on a linux cluster, each ending in something like

Run Time of 4.533 mins

I am wondering if there was an easy way in Bash scripting to run a loop or something similar on all these files *.txt and to extract the times and find what the maximum was?

标签: bash

解决方案


Given a file myFile.txt formatted like this

some
content
goes
here
...

Run Time of 4.533 mins

You can get the time with tail -n1 myFile.txt | cut -f4 -d' '

tail -n1 returns the last line

cut -d' ' cut the columns by white space

-f4 select the forth entry

follow @Mark comment to apply it to your 3000 files


推荐阅读