![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to number format a data file without using SED? | Cactus Jack | UNIX for Dummies Questions & Answers | 3 | 01-12-2008 07:47 PM |
| Number format conversion in UNIX | kamal_418 | Shell Programming and Scripting | 1 | 01-09-2008 04:12 AM |
| printing format for hexadecimal signed number | user_prady | Shell Programming and Scripting | 10 | 11-08-2007 02:34 PM |
| Help with format a number in a file | kabatsie | Shell Programming and Scripting | 3 | 09-07-2007 05:19 AM |
| How to format number/string in ksh | GNMIKE | Shell Programming and Scripting | 2 | 07-03-2005 04:44 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
number format in Perl
I try to read in a file and write out a new file with increased number at the end of each line. And I can set the initial value and increased constant from inputs.
input file: text1 text2 text3 ... text100 if I set initial value is 10, and increased constant is 0.4 output file: text1 10 text2 10.4 text3 10.8 ... text100 49.6 Code: if ($#ARGV != 3) { print "usage: do inputfile initial step outputfile\n"; exit; } $infile = $ARGV[0]; $initial = $ARGV[1]; $cons = $ARGV[2]; $outfile = $ARGV[3]; open(OF, $infile); open(NF, ">$outfile"); my $offset = $initial; # read in each line of the file while ($line = <OF>) { $line =~ s/$/ $offset/; $offset += $cons; print NF $line; } close(OF); close(NF); But my output like: text1 10 text2 10.4 text3 10.8 ... text54 31.1999999999999 text55 31.5999999999999 text56 31.9999999999999 text57 32.3999999999999 text58 32.7999999999999 ... text100 49.5999999999999 How to keep 1 decimal digit output? And why get this result? Thanks, |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|