Grep lines for number greater than given number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep lines for number greater than given number
# 1  
Old 11-20-2013
Grep lines for number greater than given number

Hello,
I am newbie to bash scripting. Could someone help me with the following.
I have log file with output as shown below
**************************LOG*************************
Code:
11/20/2013  9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data:
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=62ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=41ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=57ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=78ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=60ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=56ms TTL=125
11/20/2013  9:11:23.64 Ping statistics for xx.xx.xx.xx:
11/20/2013  9:11:23.64 Packets: Sent = 6, Received = 6, Lost = 0 (0% loss),
11/20/2013  9:11:23.64 Approximate round trip times in milli-seconds:
11/20/2013  9:11:23.64 Minimum = 41ms, Maximum = 78ms, Average = 60ms

**************************LOG*************************
I' m trying to grep for lines of an output with time >=60ms.

Desired output:
*****************************************
Code:
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=62ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=60ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=78ms TTL=125

*****************************************
Any ideas how this could best be accomplished?

Last edited by meena_2013; 11-20-2013 at 04:36 PM.. Reason: code tags
# 2  
Old 11-20-2013
Try:
Code:
grep -E 'time=([0-9]{3,}|[6-9][0-9])ms' file

or something like
Code:
awk -Ftime= '$2+0>=60' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 11-20-2013
Both worked perfectly for what I needed, thanks! Smilie
# 4  
Old 01-29-2014
Hello,

Following may also help.

Code:
awk '!/\=[6-9][0-9]/ {next}1' file_name


Output will be as follows.

Code:
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=62ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=78ms TTL=125
11/20/2013  9:11:23.64 Reply from xx.xx.xx.xx: bytes=32 time=60ms TTL=125


Thanks,
R. Singh
# 5  
Old 01-29-2014
@ravinder: that would be equivalent to awk '/\=[6-9][0-9]/' . It would not work for values that are >=100 and also the value of TTL could distort the outcome..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to output non-number lines with grep?

I want to check my data quality. I want to output the lines with non-number. I used the grep command: grep '' myfile.csv Since my file is csv file, I don't want to output the lines with comma. And I also don't want to output "." or space. But I still get the lines like the following:... (8 Replies)
Discussion started by: twotwo
8 Replies

2. Shell Programming and Scripting

How to print N number of lines before and after the grep?

Hi , My record file , need to print up to above (DATA array)(there may be n no lines ) , grep "myvalue" row now .....suggest me some options --- DATA Array--- record type xxxxx sequence type yyyyy 2 3---> data1 /dev/ --- DEVICE --- MAXIMUM_People= data_blocks= MY_value=2 xyz abc ... (0 Replies)
Discussion started by: Huvan
0 Replies

3. UNIX for Dummies Questions & Answers

Greater than specific number

please let me know how to construct if then else by comparing two numbers if it is greater than 10000. I need to do some specific task executed. can you help me out in shell scripting plz. (6 Replies)
Discussion started by: ramkumar15
6 Replies

4. UNIX for Dummies Questions & Answers

Grep SQL output file for greater than number.

Hi, This is my first post. I have a korn shell script which outputs a select statment to a file. There is only one column and one row which contains a record count of the select statement. The select statement looks something like this: SELECT COUNT(some_field) AS "count_value" ... (2 Replies)
Discussion started by: MurdocUK
2 Replies

5. Shell Programming and Scripting

Grep range of lines to print a line number on match

Hi Guru's, I am trying to grep a range of line numbers (based on match) and then look for another match which starts with a special character '$' and print the line number. I have the below code but it is actually printing the line number counting starting from the first line of the range i am... (15 Replies)
Discussion started by: Kevin Tivoli
15 Replies

6. Shell Programming and Scripting

Egrep a greater than number

data: hello mr smith 400 you all ok? hello mrs. smith 700 you all ok? hello mr. everyone 150 you all ok? hello mr. you all 199 im lad you are ok using egrep, how can i grep out only lines that have a number greater than 250? cat data | egrep ..... can't use awk here. i was... (7 Replies)
Discussion started by: SkySmart
7 Replies

7. UNIX for Dummies Questions & Answers

check if a decimal number is greater than zero

Hello, In my code I am checking to see if a variable that contains a decimal number is greater than 0 in the following manner: if do something fi However I am getting the error message (if $i for the current iteration holds 9.6352) command 9.6352 is not found How can I rectify... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

8. Shell Programming and Scripting

count the number of lines that start with the number

I have a file with contents similar to this. abcd 1234 4567 7666 jdjdjd 89289 9382 92 jksdj 9823 298 I want to write a shell script which count the number of lines that start with the number (disregard the lines starting with alphabets) (1 Reply)
Discussion started by: grajp002
1 Replies

9. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

10. Shell Programming and Scripting

number of lines returned from a grep command

hi all, from a shell (ksh) script, i am doing a 'grep'. how do i find out the number of lines returned from that 'grep' command ?? thanks in advance. (4 Replies)
Discussion started by: cesarNZ
4 Replies
Login or Register to Ask a Question