grep 2000 and higher


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep 2000 and higher
# 1  
Old 01-08-2010
grep 2000 and higher

i have content that looks like this:
0003326050 A E LITHO
0023823422 AMERICAN RED CROSS
0005713642 ARUP LABORATORIES
0003206450 CAEL
0002519930 CARDINAL HEALTH
0002619063 FISHER HEALTHCAR
0065203177 OWENS & MINOR INC
0016552938 STAPLES INC
0000002001 MSC
0000002000 KY Mut
0000000100 VA Hosp

i'd like to grep anything that higher than 2000 only.
# 2  
Old 01-08-2010
Hi.

I presume this is what you mean:
Code:
awk '$1 > 2000' input_file

# 3  
Old 01-08-2010
grep has no understanding of numerals as numbers, so can't do what you want. Here's a shell loop for it. And there's probably an awk one-liner to do it.

Code:
#!/bin/sh

while read VAL TEXT
do
        if [ "$VAL" -gt "2000" ]
        then
                echo "$VAL" "$TEXT"
        fi
done < input

[edit] Heh. Beaten to the punch by the awk folk again. Smilie
# 4  
Old 01-08-2010
Tools Here is one approach, there are many

Code:
C:\cygwin\tmp>cat 2vars.txt
0003326050 A E LITHO
0023823422 AMERICAN RED CROSS
0005713642 ARUP LABORATORIES
0003206450 CAEL
0002519930 CARDINAL HEALTH
0002619063 FISHER HEALTHCAR
0065203177 OWENS & MINOR INC
0016552938 STAPLES INC
0000002001 MSC
0000002000 KY Mut
0000000100 VA Hosp

C:\cygwin\tmp>cat 2vars.txt | grep "^[0-9]\{6\}[2-9]"
0003326050 A E LITHO
0023823422 AMERICAN RED CROSS
0005713642 ARUP LABORATORIES
0003206450 CAEL
0002519930 CARDINAL HEALTH
0002619063 FISHER HEALTHCAR
0065203177 OWENS & MINOR INC
0016552938 STAPLES INC
0000002001 MSC
0000002000 KY Mut

# 5  
Old 01-08-2010
That will work for 2000-9999, but will fail for things like 30000. You'd need to or multiple patterns together to get all the needed possibilities, or just use something that actually understands the digits like awk or shell.
# 6  
Old 01-08-2010
scottn,

you never fail to answer my post. thank you very much my friend.
# 7  
Old 01-08-2010
Tools Corona is correct in the error of my prior logic for grep.

Maybe this one then....
Code:
C:\cygwin\tmp>cat 2vars.txt | grep -v "^000000[01]"
0003326050 A E LITHO
0023823422 AMERICAN RED CROSS
0005713642 ARUP LABORATORIES
0003206450 CAEL
0002519930 CARDINAL HEALTH
0002619063 FISHER HEALTHCAR
0065203177 OWENS & MINOR INC
0016552938 STAPLES INC
0000002001 MSC
0000002000 KY Mut
0000031001 TEST

Note I added a line at end of text file to test out.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. OS X (Apple)

A simple plaything for a 19 month old and higher.

This thread today reminded me of it: https://www.unix.com/shell-programming-and-scripting/279465-larger-window.html#post303021017 This is OSX 10.13.6 and greater centric only. This expands the terminal window on the fly in bash. You initially need to put the standard terminal window to the top... (0 Replies)
Discussion started by: wisecracker
0 Replies

2. UNIX for Dummies Questions & Answers

Remove when date is higher

Dear Masters, I need to eliminate lines from file input 2 when the date in column 1 more than date in column 1 in file input 1 input 1 20141101|USA|CANSEL|496420000 20141101|USA|CANUT|1069740000 20141101|USA|CANTENG|625920000 20141102|USA|CANUT|413180000 20141103|USA|CANSEL|1364245000... (5 Replies)
Discussion started by: radius
5 Replies

3. AIX

THCOUNT (THCNT) higher than ThreadLimit for httpd process?

One issue I could see on AIX 5.3: At one of my customer they have got the ThreadLimit of 2500 set on web server in httpd.conf file. Currently 2000 users have logged in each attaing a single instance of httpd. While in ps -ef for httpd process it is showing thread count (thcount) almost 3000.... (3 Replies)
Discussion started by: aarora_98
3 Replies

4. Shell Programming and Scripting

if test for higher value between 2 decimal numbers

Hi I would like to test for a max number value. It may be a decimal so I know I have to pipe into bc. I just cannot get the syntax for this to work. I cannot get passed an error with the bracket - see below. Any help appreciated. Regards Ewan This works: /export/home/ewan> cat... (5 Replies)
Discussion started by: emjs
5 Replies

5. What is on Your Mind?

Where to find higher consulting rates?

Have any IT consultants here been on a project where you knew the bill rate was really high but you only got a tiny piece of it (like paid $60/hr and billed out around $200)? Does anyone know of a company that pays consultants well - like 70-80% or more of what they're getting? (5 Replies)
Discussion started by: apierce
5 Replies

6. Shell Programming and Scripting

Checking for higher usage and mark it

Hi Gurus, I'm using HPUX B.11.23 U ia64 with sh shell. Is it possible to insert a word "Warning" in the end of this line if there is high percentage? For example: if the percentage is higher than 80%? Sample data: /dev/vgsap/TEST1 /oracle/TST/TEST1 9.89 GB 8.37 GB ... (11 Replies)
Discussion started by: superHonda123
11 Replies

7. UNIX for Advanced & Expert Users

Backgrounding process with higher priority

I have been troubleshooting a mysterious performance problem with the nightly batch programs on our primary system for quite some time and just found something very interesting. All batch processes are running with a nice value of 24. I don't know what the default is on other systems but I do know... (3 Replies)
Discussion started by: keelba
3 Replies

8. UNIX for Dummies Questions & Answers

Fireblade(SUN) need Solaris 8 or Higher ?

Hi, Is it right, that the Sun fireblade need Solaris 8 or higher? Thanks for your response. regards joerg (1 Reply)
Discussion started by: joerg
1 Replies
Login or Register to Ask a Question