Srinivas,
Here is an awk script I wrote some time ago for adding commas (every 3
digits) into a number. Command line format would be something like:
echo 1234567 | awk -f comma.awk
Where "comma.awk" would be the filename of the below script.
=======
#
# awk program to add commas in a number every 3 digits
#
{
# ... save off the number
num = $1 ;
# ... get length of the number entered
lng = length($1) ;
# ... determine the number of commas that needs to be added to the
number entered
commas = int(lng/3) ;
# ... determine number of remaining numbers (modulo arithmetic)
lose1 = lng % 3 ;
# ... no remaining numbers AND number needs at least ONE comma then
# ... subtract one from comma count before we start
if (( ! lose1 ) && ( commas > 0 ))
{
commas -= 1 ;
}
# ... initialize the string variable to an empty string
num = "" ;
for( x = 1 ; x <= commas ; x++ )
{
# ... add 3 to a loop counter
y += 3
# ... starting at the end of the number, strip off 3 chars at a time
get = substr($1,lng-y+1,3) ;
if ( x == 1 )
{
num = get ;
}
else
{
# ... add a comma to the string
num = get "," num ;
}
}
# ... if have less than another set of 3 numbers, then
# ... add what's left of the number to the front
rest = lng - (commas * 3 )
if ( rest > 0 )
{
# ... if number was shorter than 3 chars then print it without comma
if(lng>3)
{
get = substr($1,1,rest) ;
num = get "," num ;
}
else
{
num = substr($1,1,rest) ;
}
}
print num ;
}
Sorry, but can't help with the rest of your request, beyond my skill
set right now.
Good luck,
dan
________________________________
From: geeksthatgawk@yahoogroups.com
[mailto:geeksthatgawk@yahoogroups.com] On Behalf Of schpanich
Sent: Thursday, September 07, 2006 12:14 AM
To: geeksthatgawk@yahoogroups.com
Subject: [Geeks that Gawk] can we call awkscript from a webbrowser
Hello friends,
My name is Srinivas Chakrpani, I have so many doubts in awk scripting.
The scripting tools like perl,php,python can call from a web browser.
Just by modification the Add-Handler types in httpd.conf file (for
apache web server). Is it possible in the same way we can call any
awkscript from the webserver. If so please give the details what we
have to do to the file/ permissions to files and with a example script.
Moreover I want to format the numbers in awk that is
123456 as 1,23,456 how is it possible if possible please share me with
a example
I want access multiple files in awk is it possible?
Any scripts in awk are please send to my mail address giving below
chs.chakrapani@... <mailto:chs.chakrapani%40licindia.com>
This email may contain confidential and privileged material for the sole use of
the intended recipient(s) and only for those purposes previously or herein
authorized by the sender. Any review, use, distribution or disclosure by others,
or use by the recipient for unauthorized purposes, is strictly prohibited. If
you are not the intended recipient (or authorized to receive for the recipient),
please contact the sender by reply email and delete all copies of this message.
Disclaimer:
This email may contain confidential and privileged material for the sole use of
the intended recipient(s) and only for those purposes previously or herein
authorized by the sender. Any review, use, distribution or disclosure by others,
or use by the recipient for unauthorized purposes, is strictly prohibited. If
you are not the intended recipient (or authorized to receive for the recipient),
please contact the sender by reply email and delete all copies of this message.
[Non-text portions of this message have been removed]