Line by line getting a certain file name has a certain value

Hello

I have a file like this:

20140403_093024basd.r   56.4%
20140430_165240basd.r   55.0%
20140501_143537basd.r   60.9%
20140502_091520basd.r   54.7%
20140504_201824basd.r   35.5%
20140505_110843basd.r   58.3%
20140515_101642basd.r   68.8%
20140516_110140basd.r   40.7%
20140518_010232basd.r   49.0%
20140518_115921basd.r   50.4%
20140521_002112basd.r   63.5%
20140521_162154basd.r   72.3%

The first column is several file names in my directory and second column a number to detect some of them which is greater than 80%. So, I want to get the file names in the first column which are greater than 80%. How can I do that?

Please help!

Thank you

Hi,
Maybe :

awk '/ [8-9][0-9][.0-9]*%| 100[.0-9]*%/ && $0=$1' file

Regards.

1 Like

An AWK version

awk '$2>80{print $1}' jeo_fb.file

A Perl version

perl -nale 'print $F[0] if $F[1]>80' jeo_fb.file
1 Like

That is a tiny bit too simple. Since $2 expands to a string containing a non-numeric character (the percent sign), the comparison will be a string comparison instead of a numeric comparison. Therefore, input like:

20140521_162154basd.r  9.3%

will also print the (unwanted) filename and the input:

20140521_162154basd.r 100.0%

will not print the desired filename. With the slight modification:

awk '$2+0>80{print $1}' file

you get the desired results.

1 Like

Thank you. It works