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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Arg List too Long in SCP chris1234 UNIX for Dummies Questions & Answers 5 02-27-2008 05:40 AM
ksh: /usr/bin/ls: arg list too long jitindrabappa UNIX for Dummies Questions & Answers 2 10-12-2006 12:08 AM
ls -t arg list too long CSU_Ram UNIX for Dummies Questions & Answers 4 05-05-2005 07:19 AM
arg list too long encrypted UNIX for Advanced & Expert Users 8 11-12-2004 03:38 AM
arg list too long vingupta UNIX for Dummies Questions & Answers 5 08-02-2001 08:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-14-2005
Registered User
 

Join Date: May 2004
Posts: 45
Subtract 100 from first field in long list? Simple manipulation?

It sounds so easy to do.

I have a file thats laid out like this..


number text text text text (etc about 15 times with various text fields)

I want to take the first field, "number", subtract 100 from it, and then put it back in the file. a simple little manipulation of the first field in the file.

is there an easy way to do this?

So if it looks like


14523 a b c d e f
24245 g h i j k l

it would end up being

14423 a b c d e f
24145 g h i j k
Reply With Quote
Forum Sponsor
  #2  
Old 09-14-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
 awk '{ $1=$1-100; print $0} ' filename
Reply With Quote
  #3  
Old 09-14-2005
Registered User
 

Join Date: May 2004
Posts: 45
Well that pretty much worked..

One thing though, why does it convert everything to scientific form?

When I do a manipulation on large numbers the results look something like this:

1.12649e+09

Ideas?
Reply With Quote
  #4  
Old 09-14-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Yes. $1 was a string on input - it got run thru a math operation so now it's a number.
Let's try to force it back to a string.
Code:
awk '{ $1=$1-100; $1=sprintf("%s", $1); print $0} ' filename
Reply With Quote
  #5  
Old 09-14-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
Quote:
Originally Posted by jim mcnamara
Yes. $1 was a string on input - it got run thru a math operation so now it's a number.
Let's try to force it back to a string.
Code:
awk '{ $1=$1-100; $1=sprintf("%s", $1); print $0} ' filename
Revised:
Code:
awk '{ $1=sprintf("%s", $1-100); print}' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0