The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: insert a decimal point
aznjason
Newbie
Rank: 1



UID 63
Digest Posts 0
Credits 0
Posts 45
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 18, 2007 11:17 AM  Profile | P.M. 
insert a decimal point



insert a decimal point



hi all. using /bin/sh on an hpux system.

i want to place a decimal in the field 2 charactors from the right (yes, converting to currency). the field lengths are variable. here's what i'm doing:

exec < filename
while read field1 field2
do
field1="echo $field1 | sed 'syntax that will insert . 2 chars before rightmost' "

done

thanks in advance!!!!!


Top
mightyb
Newbie
Rank: 1



UID 264
Digest Posts 0
Credits 0
Posts 40
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 18, 2007 11:17 AM  Profile | P.M. 
if number may be one digit only, you can use this sed command :

code:
echo "1234" | sed 's/..$/.&/;t;s/^.$/.0&/'  -> 12.23
echo    "1" | sed 's/..$/.&/;t;s/^.$/.0&/'  -> .01
on my aix box, i have a problem with the 't' command inside sed (all the string after t is considered as being the label to branch to). if you have the same problem, you can remove the 't;' part.
Top
linkmanager
Newbie
Rank: 1



UID 235
Digest Posts 0
Credits 0
Posts 38
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 18, 2007 11:17 AM  Profile | P.M. 
nice one, aigles!
Top
 

 

All times are GMT, the time now is Jul 31, 2010 03:33 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.005122 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP