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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line by line getting a certain file name has a certain value
# 1  
Old 01-03-2016
Line by line getting a certain file name has a certain value

Hello

I have a file like this:

Code:
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

Last edited by Don Cragun; 01-03-2016 at 09:21 PM.. Reason: Add CODE tags.
# 2  
Old 01-03-2016
Hi,
Maybe :
Code:
awk '/ [8-9][0-9][.0-9]*%| 100[.0-9]*%/ && $0=$1' file

Regards.
This User Gave Thanks to disedorgue For This Post:
# 3  
Old 01-03-2016
An AWK version
Code:
awk '$2>80{print $1}' jeo_fb.file

A Perl version
Code:
perl -nale 'print $F[0] if $F[1]>80' jeo_fb.file


Last edited by Aia; 01-03-2016 at 06:27 PM..
This User Gave Thanks to Aia For This Post:
# 4  
Old 01-03-2016
Quote:
Originally Posted by Aia
An AWK version
Code:
awk '$2>80{print $1}' jeo_fb.file

... ... ...
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:
Code:
20140521_162154basd.r  9.3%

will also print the (unwanted) filename and the input:
Code:
20140521_162154basd.r 100.0%

will not print the desired filename. With the slight modification:
Code:
awk '$2+0>80{print $1}' file

you get the desired results.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 01-04-2016
Quote:
Originally Posted by Don Cragun
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:
Code:
20140521_162154basd.r  9.3%

will also print the (unwanted) filename and the input:
Code:
20140521_162154basd.r 100.0%

will not print the desired filename. With the slight modification:
Code:
awk '$2+0>80{print $1}' file

you get the desired results.

Thank you. It works
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

5. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

6. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

7. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

8. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

9. Shell Programming and Scripting

Reading a file line by line and processing for each line

Hi, I am a beginner in shell scripting. I have written the following script, which is supposed to process the while loop for each line in the sid_home.txt file. But I'm getting the 'end of file' unexpected for the last line. The file sid_home.txt gets generated as expected, but the script... (6 Replies)
Discussion started by: sagarparadkar
6 Replies
Login or Register to Ask a Question