The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK greater than? dlam Shell Programming and Scripting 6 03-10-2008 02:43 AM
AWK greater than 200 insania Shell Programming and Scripting 2 02-05-2007 03:03 PM
How to perform calculations using numbers greater than 2150000000. stevefox Shell Programming and Scripting 3 11-22-2005 07:21 AM
Greater Than Lem2003 Shell Programming and Scripting 2 08-29-2003 11:06 AM
Sed - Replacing numbers w/asteriks in random location in a file giannicello UNIX for Dummies Questions & Answers 9 10-04-2001 01:03 AM

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 06-04-2008
vrms vrms is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
replacing numbers greater than 0 with 1

I have some ASCII files containing numerous numbers. What I'd like to do is replace all numbers greater than 0 with 1.

Examples of the numbers include: - 000011 and 000042

Thanks
  #2 (permalink)  
Old 06-04-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by vrms View Post
I have some ASCII files containing numerous numbers. What I'd like to do is replace all numbers greater than 0 with 1.

Examples of the numbers include: - 000011 and 000042

Thanks
Pls show a sample file and a desired output.
  #3 (permalink)  
Old 06-04-2008
vrms vrms is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
OK I cant show a complete file (They are big!)

So this is a section of one of the text files

-99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 001037 001015 000946 001044 001059 001049 001074 001064 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 001053 001031 000812 000993 000663 001089 001071 000994 001066 001099 001104 001073 000959 000982 001062 001039 001020 001041 001071 001020 001041 000972 000941 000944 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999 -99999


Basically I want to ignore the -99999's and convert all other numbers EQUAL OR GREATER THAN 0 (I apologise I didn't put the EQUAL in before!) to 1.

Thanks
  #4 (permalink)  
Old 06-04-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
something along these lines:
Code:
nawk '{for(i=1; i<=NF; i++)  $i=($i>=0) ? 1 : $i}1' myFile
  #5 (permalink)  
Old 06-04-2008
vrms vrms is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
Thanks vgersh99 that works very well

thank you

vrms
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 06:22 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