How to grep a pattern having value greater than 123 in a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep a pattern having value greater than 123 in a file?
# 1  
Old 05-20-2011
How to grep a pattern having value greater than 123 in a file?

Hi,

I have a dynamically growing ascii file which has large data (both text and digits). I need to grep those lines having value greater than '123'. These numeric values may appear at anywhere in the line, hence I could not use awk to split to columns.

So, please help me with the grep regular expression pattern for this.
# 2  
Old 05-20-2011
Try this code:

Code:
 
grep "12[4-9][0-9]*" filename

# 3  
Old 05-20-2011
Try:
Code:
perl -ne 'print if grep {$_>123} /(\d{3,})/g' file

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 05-23-2011
Quote:
Originally Posted by 116@434
Try this code:

Code:
 
grep "12[4-9][0-9]*" filename

Thanks, but this suggestion locks down the first 2 digits should be '12'. But I want to get any value that is greater than 123

---------- Post updated at 10:11 AM ---------- Previous update was at 10:11 AM ----------

Quote:
Originally Posted by bartus11
Try:
Code:
perl -ne 'print if grep {$_>123} /(\d{3,})/g' file

Is that possible to do this using only 'grep'?
# 5  
Old 05-23-2011
This should work provided if you have the number seperated by space

Code:
grep -v -e " [0-9] " -e " [0-9][0-9] " -e " 12[0-3] " filename

I am trying to eliminate all one,two,three digit numbers but greater than 123
# 6  
Old 05-23-2011
Quote:
Originally Posted by kumaran_5555
This should work provided if you have the number seperated by space

Code:
grep -v -e " [0-9] " -e " [0-9][0-9] " -e " 12[0-3] " filename

I am trying to eliminate all one,two,three digit numbers but greater than 123
But, this fails suppose if the file is having a line like this:
"rdate NTPserver login 115 /var/log".

This line is not supposed to be shown in the output as 115 < 123. But, it is still being shown Smilie
# 7  
Old 05-23-2011
Code:
# echo "rdate NTPserver login 140 /var/log"|sed '/\b0*[0-9]\b\|\b0*[0-9][0-9]\b\|0*1[1-2][0-3]\|0*1[0-1][0-9]/d'
rdate NTPserver login 140 /var/log

Code:
# echo "rdate NTPserver login 121 /var/log"|sed '/\b0*[0-9]\b\|\b0*[0-9][0-9]\b\|0*1[1-2][0-3]\|0*1[0-1][0-9]/d'

regards
ygemici

Last edited by ygemici; 05-23-2011 at 06:08 AM..
This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

2. 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

3. Shell Programming and Scripting

Grep a file pattern in another

Hi I'm new to the forum, so I'd apologize for any error in the format of the post. I'm trying to find a file content in another one using: grep -w -f file1 file2 file1 GJA7 TSC file 2 GJC1 GJA7 TSC1 TSC (11 Replies)
Discussion started by: flyfisherman
11 Replies

4. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

5. UNIX for Dummies Questions & Answers

look for file size greater than "0" of specific pattern and move those to another directory

Hi , i have some files of specific pattern ...i need to look for files which are having size greater than zero and move those files to another directory.. Ex... abc_0702, abc_0709, abc_782 abc_1234 ...etc need to find out which is having the size >0 and move those to target directory..... (7 Replies)
Discussion started by: dssyadav
7 Replies

6. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

7. Shell Programming and Scripting

grep /target greater than time period??

Hey guys, I'm fairly new at unix shell scripting and I have a quick question. Quick overview I devolped a script where I generate a file ..and I want to grep any time greater than 30 minutes. What i do is runa command to generates the below and puts it into a file: I run ./ggsci << endit... (4 Replies)
Discussion started by: nomiezvr4
4 Replies

8. Shell Programming and Scripting

Need to Grep or awk a logfile for greater than value

Hello all Hoping someone would be kind enough to suggest a solution to a problem i have, and see if maybe i can even do this without a script. Essentially i have a very large log file, and within it each line had a value called TTMT, and it records a variable number in the following way, so... (6 Replies)
Discussion started by: 1905
6 Replies

9. Shell Programming and Scripting

grep for greater than 12 chars

Hi, is there any way in grep to grep for a certain number of characters? For example I have a list of customerIDs, I want to grep for all greater than 12 characters? (2 Replies)
Discussion started by: borderblaster
2 Replies

10. UNIX for Dummies Questions & Answers

Grep a pattern in gz file

I have a set of .gz files. I need to grep a pattern and need to find out the file in which that pattern occurs. zgrep in not available in my server.Any other options available for searching a pattern without unzipping the .gz files. (2 Replies)
Discussion started by: rprajendran
2 Replies
Login or Register to Ask a Question

Featured Tech Videos