Sorry, but grep is not an option for this. The grep family of utilities doesn't do arithmetic (including numeric comparisons), it matches strings.
------------------------
I take it back. There is a way to do it, it is just messy (and you will need to re-engineer a different expression for each value you're trying to compare). What do you mean by field 2? In you example is field 2 supposed to be 12 or 19? Will you ever have negative numbers? For non-zero values, will there ever be a leading 0?
With grep you don't have $2 to specify the second field and once you have the second field you don't have >.
Last edited by Don Cragun; 05-06-2013 at 02:51 PM..
Reason: Need more details.
This User Gave Thanks to Don Cragun For This Post:
grep does not have a way to tokenise the input like awk/perl (it's not built to do so). You can cook a pattern to match all the way until the required field, but then.. you have awk/perl.
To check if number in field #2 > 10 :
This User Gave Thanks to balajesuri For This Post:
grep does not have a way to tokenise the input like awk/perl (it's not built to do so). You can cook a pattern to match all the way until the required field, but then.. you have awk/perl.
To check if number in field #2 > 10 :
looks like this could be the answer. although it would be dirty.
in this case, the bolded would be considered the second column/field:
---------- Post updated at 02:04 PM ---------- Previous update was at 01:46 PM ----------
sorry guys, i'm having issues with this:
i want to show whichever line has a value of 5 or more. i'm trying to use this:
but it doesn't seem to be working.
---------- Post updated at 02:10 PM ---------- Previous update was at 02:04 PM ----------
Quote:
Originally Posted by Don Cragun
Sorry, but grep is not an option for this. The grep family of utilities doesn't do arithmetic (including numeric comparisons), it matches strings.
------------------------
I take it back. There is a way to do it, it is just messy (and you will need to re-engineer a different expression for each value you're trying to compare). What do you mean by field 2? In you example is field 2 supposed to be 12 or 19? Will you ever have negative numbers? For non-zero values, will there ever be a leading 0?
With grep you don't have $2 to specify the second field and once you have the second field you don't have >.
In this example, the 2nd field would be 19. there's not gonna be a negative number.
To match $3 >= 5, followed by "Mailbox" when your field terminator is '|' try:
After finding the 2nd "|" on the line it ignores any number of spaces, any number of leading zeros, and then it looks for a single digit that is 5 through 9 or two or more digits starting with 1 through 9.
To match $3 > 20, followed by "Mailbox" try:
After finding the 2nd "|" on the line it ignores any number of spaces, any number of leading zeros, and then looks for a two digit string that is 21-29, a two digit string that is 30-99, or a 3 or more digit string that is greater than or equal to 100.
As you can see you'll need to craft the ERE to use to select the numeric values you're trying to match. Hope these examples help.
Last edited by Don Cragun; 05-06-2013 at 05:30 PM..
Reason: fixed tag
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)
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)
Hello,
I am newbie to bash scripting. Could someone help me with the following.
I have log file with output as shown below
**************************LOG*************************
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:... (4 Replies)
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)
A file
2400 2800 PSC000289
3200 3896 PCS000289
3333 3666 PCS000221
222 1000 PCS000222
3299 3600 PSC000289
Question is while if third column is PCS000289
and first column should be greater than 3000, then replace PCS000289 by YES,
remaining the others column same.
... (1 Reply)
Hi all,
I have a tab-delimited text file of size 10Mb. I am trying to count the number of lines using,
grep -c . sample.txtor
wc -l < sample.txt or
awk 'END {print NR}' sample.txtAll these commands shows the count as 1, which means they are reading only the first header line of the file.... (3 Replies)
Hi All,
I am running a command from a remote server using ssh to different servers. I will get a output like below with 4 columns. I want to grab line which is having a coulmn which grate than or equal to 50. How can I do it with Awk or sed ??. I add a space to first row with sed 's/::/:: /g' to... (4 Replies)
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)
Hello all
Im trying to write one liner that will show me results only if the result of the expression is greater then 0
For example:
I do :
find . -name "*.dsp" | xargs grep -c SecurityHandler
the result are :
./foo/blah/a.dsp:0
./foo/blah1/b.dsp:1
./foo/blah2/c.dsp:2... (1 Reply)