The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix noob help with awk? AnnaLynn Shell Programming and Scripting 11 04-01-2008 10:29 AM
Unix Noob, wat do i need etc skylin3fr3ak UNIX for Dummies Questions & Answers 2 02-24-2008 11:17 AM
Noob sorting question Hexabah UNIX for Dummies Questions & Answers 1 02-11-2007 04:57 AM
Question about compiling (noob) arya6000 High Level Programming 9 12-11-2006 01:28 AM
complete noob avdrummerboy UNIX for Dummies Questions & Answers 3 12-04-2006 12:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-15-2007
kirkm76 kirkm76 is offline
Registered User
  
 

Join Date: May 2007
Posts: 9
Noob question on comparing #'s.

I have a file with 3 digit numbers in it formatted as such:
123
065
321

How would I go about seeing if each number is less than 100 and if so outputting it to another file

Yes, I am a bit of a noob. I have tried with grep but I don't think it'll work.

Any general direction would be appreciated then I'll go bang my head into the wall.
  #2 (permalink)  
Old 05-15-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100

Code:
awk '$0 < 100 {print}' infile > newfile

Cheers,
ZB
  #3 (permalink)  
Old 05-16-2007
kirkm76 kirkm76 is offline
Registered User
  
 

Join Date: May 2007
Posts: 9
Great, now can I do this...

Thanks. Now just out of curiosity, if I wanted to grab the numbers between 65 and 100 and count them and then between 101 and 450 could I do that in a similar manner.

Also, can awk use the number in a variable in a script rather than a hard coded "100" as in the previous reply. Lastly, do I need to output awk to a file to get the count or can I do it on the fly. I appreciate the help.
  #4 (permalink)  
Old 05-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
Quote:
Originally Posted by kirkm76
Thanks. Now just out of curiosity, if I wanted to grab the numbers between 65 and 100 and count them and then between 101 and 450 could I do that in a similar manner.

Also, can awk use the number in a variable in a script rather than a hard coded "100" as in the previous reply. Lastly, do I need to output awk to a file to get the count or can I do it on the fly. I appreciate the help.
something like this

Code:
awk '65<$0 && $0<=100{c1++}
       101<$0 && $<=450{c2++}
END{ 
    print "Count of 65 to 100: " c1
    print "Count of 101 to 450: " c2  
} ' file

  #5 (permalink)  
Old 05-16-2007
kirkm76 kirkm76 is offline
Registered User
  
 

Join Date: May 2007
Posts: 9
how about this?

Thanks...I managed to get that far this morning. What I am wondering now is can I check to see if a number is less than a variable defined earlier in the script, sort of like below:

FIRST1=65
LAST1=100

awk '(($0 > FIRST1) && ($0 < LAST1))'
  #6 (permalink)  
Old 05-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
Quote:
Originally Posted by kirkm76
Thanks...I managed to get that far this morning. What I am wondering now is can I check to see if a number is less than a variable defined earlier in the script, sort of like below:

FIRST1=65
LAST1=100

awk '(($0 > FIRST1) && ($0 < LAST1))'
you pass in the variable like this:

Code:
awk -v first=$FIRST -v last=$LAST1 '{ }'

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0