system
September 14, 2005, 8:51am
1
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
awk '{ $1=$1-100; print $0} ' filename
system
September 14, 2005, 11:00am
3
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?
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.
awk '{ $1=$1-100; $1=sprintf("%s", $1); print $0} ' filename
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.
awk '{ $1=$1-100; $1=sprintf("%s", $1); print $0} ' filename
Revised:
awk '{ $1=sprintf("%s", $1-100); print}' filename