![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
awk '{ $1=$1-100; print $0} ' filename
|
|
#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? |
|
#4
|
|||
|
|||
|
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
|
|
#5
|
|||
|
|||
|
Quote:
Code:
awk '{ $1=sprintf("%s", $1-100); print}' filename
|
|||
| Google The UNIX and Linux Forums |