Visit Our UNIX and Linux User Community


convert 1012345601 to $10,123,456.01


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers convert 1012345601 to $10,123,456.01
# 1  
Old 04-11-2008
convert 1012345601 to $10,123,456.01

i'd like to convert 1012345601 to $10,123,456.01 via aix.
# 2  
Old 04-12-2008
We can do that with just a simple sed command...
Code:
$ echo 1012345601 | sed -e 's/\(.*\)\(..\)$/\1.\2/' -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' -e 's/^/$/'
$10,123,456.01
$

Well, ok... maybe that is a mid-level sed command... Smilie
# 3  
Old 04-12-2008
Using awk:

Code:
echo 1012345601 | awk '{split(1012345601,a,"")

print "$"a[1] a[2]","a[3] a[4] a[5]","a[6] a[7] a[8]"."a[9] a[10]}'

# 4  
Old 04-12-2008
Thanks for both you guys; worked.
# 5  
Old 04-15-2008
now i run into another road block. what if i have 0001012345601, i only want to read as $10,123,456.01
# 6  
Old 04-15-2008
Code:
$ echo 0001012345601 | sed -e 's/^0*//' -e 's/\(.*\)\(..\)$/\1.\2/' -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' -e 's/^/$/'
$10,123,456.01

# 7  
Old 04-15-2008
thanks. you guys are AWSOME!
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #227
Difficulty: Easy
According to NetMarketShare, in September 2019 BSD had a 0.01% global market share of the desktop computing market.
True or False?

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep a pattern having value greater than 123 in a file?

Hi, I have a dynamically growing ascii file which has large data (both text and digits). I need to grep those lines having value greater than '123'. These numeric values may appear at anywhere in the line, hence I could not use awk to split to columns. So, please help me with the grep regular... (12 Replies)
Discussion started by: royalibrahim
12 Replies

2. Shell Programming and Scripting

Increment ABC-123 by 1!!

in a shell script, i hav a variable declared as "ABC-123". i want to incriment th value ABC-123 by 1 so that the result will be ABC-124. Can anyone suggest a solution in shell scripting.. (4 Replies)
Discussion started by: pgmfourms
4 Replies

3. Shell Programming and Scripting

to make 1 2 3 into 123

suppose u have a file ABC ADFA AFAF AGBA AHHAH AJJA AJKA AJAJ AJAJA AJAJAJ AHAB AAAJ AJAJA AKK AJAJAA means gaps have to replaced and see also there will be gaps so output shud be ABCADFAAFAFAGBAAHHAHAJJAAJKAAJAJAJAJAAJAJAJAHABAAAJJAJAAKKAJAJAA Thanks (2 Replies)
Discussion started by: cdfd123
2 Replies

Featured Tech Videos