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?
# 8  
Old 05-23-2011
I have missed one pattern.

Code:
 for ((i=0;i<130;i++)); do echo " $i "|grep -v -e " [0-9] " -e " [0-9][0-9] " -e " 1[0-1][0-9] " -e " 12[0-3] "

 124
 125
 126
 127
 128
 129

# 9  
Old 09-07-2011
how would you do the same thing but only for values before the first "," in each line AND for decimal numbers ie 400.232352,ATK4875739,234,2,33,3?
# 10  
Old 09-07-2011
Quote:
Originally Posted by herot
how would you do the same thing but only for values before the first "," in each line AND for decimal numbers ie 400.232352,ATK4875739,234,2,33,3?
Code:
$
$
$ cat f18
400.232352,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
100.23,XYZ,0                      # don't show, because no. from beginning to 1st comma is decimal but < 123
125,ABC,0                         # don't show, because no. from beginning to 1st comma is not a decimal
12PQR,DEF,0                       # don't show, because chars from beginning to 1st comma do not represent a number
123.000001,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
-100.23,MNO,0                     # don't show, because no. from beginning to 1st comma is decimal but < 123
$
$
$ perl -lne '/^(.*?),.*/; print if $1 !~ /[a-zA-Z]/ and int($1) != $1 and $1 > 123' f18
400.232352,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
123.000001,ATK4875739,234,2,33,3  # show, because no. from beginning to 1st comma is decimal and > 123
$
$
$

tyler_durden
# 11  
Old 09-12-2011
Quote:
Originally Posted by kumaran_5555
I have missed one pattern.
Code:
 for ((i=0;i<130;i++)); do echo " $i "|grep -v -e " [0-9] " -e " [0-9][0-9] " -e " 1[0-1][0-9] " -e " 12[0-3] "

 124
 125
 126
 127
 128
 129

Thanks kumaran_5555 for this. But, why this works only when there is a space before and after the pattern?
# 12  
Old 09-12-2011
Code:
awk -F, '/,/{if($1>123){print}next}{x=$0;gsub(/[^0-9]/,"");if($0+0>123){print x} }' inputFile

Something like this?

Code:
$ cat file
rdate NTPserver login 115 /var/log
rdate NTPserver login 123.4 /var/log
rdate NTPserver login 123 /var/log
rdate NTPserver login 124 /var/log
400.232352,ATK4875739,234,2,33,3
110.232352,ATK4875739,234,2,33,3

$ awk -F, '/,/{if($1>123){print}next}{x=$0;gsub(/[^0-9]/,"");if($0+0>123){print x} }' file
rdate NTPserver login 123.4 /var/log
rdate NTPserver login 124 /var/log
400.232352,ATK4875739,234,2,33,3

--ahamed

Last edited by ahamed101; 09-12-2011 at 03:33 AM.. Reason: Some minor modifications
This User Gave Thanks to ahamed101 For This Post:
# 13  
Old 09-12-2011
hi,

if you have gawk installed, this seems to work :
Code:
echo "rdate NTPserver login 140 /var/log
rdate NTPserver login 121 /var/log" | \
   awk '{var=$0; var=gensub(/[^[:digit:]*]/,"","g",var); if ( var > 123 ) { print $0}}'

This User Gave Thanks to daPeach 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