Guys, please help! I am currently using an AIX server however whenever I tried to use the typeset -F3, the variable is resulting with a "#".
In the given example below, I declared x to be a decimal holding 3 decimal places = 1.455. However whenever I tried to echo the $x, the resulting value became 3#1. Please let me know how can I make $x to be exactly the value I assign to this variable (1.455). Thanks in advance!
Actually this is the code I have. Here, I am using two files. First is the cluster_file.list and item_sales.dat.
The script will parse the cluster_file.list and check the total sales for the cluster. If total sales of the cluster is greater than 100 and less than 200 then adjustment needs to be done. The adjustment will be 200 - the total sales of the cluster / divided by the total lines of the cluster. The calculated adjustment will be distributed/added to all ITEMS under the cluster.
#==================================================================================
# f_adjustMinimums
#----------------------------------------------------------------------------------
# DESCRIPTION:
# This function will be used to adjust the sales based on minimum
#
# Parameter
# a. Cluster List File
# b. Sales File
#----------------------------------------------------------------------------------
function f_adjustMinimums {
if [[ $DETAIL_LOG = "true" ]]; then set -x; fi; FUNCTION=$0
# Assign Cluster and Sales File into Arrays
CLUSTER=`cat $1`
SALES=`cat $2`
set -A CLUSTER_TEMP
# Adjust sales based on minimum = 200
for cluster in "${CLUSTER[*]}"
do
# Get the total sales of cluster being evaluated
total_sales=`echo "${SALES[*]}"|grep $cluster|awk -F"," '{x+=$3} END {print x}'`
# Validate the total sales of cluster being evaluated if sales > 100 and sales < 200
if [[ $total_sales -gt 100 && $total_sales -lt 200 ]]; then
# Get the total no. of lines of cluster being evaluated
typeset -i cluster_lines=`echo "${SALES[*]}"|grep $cluster|wc -l`
# Get the difference between 200 and total_sales
typeset -F3 diff="200 - $total_sales"
# Calculate the quotient to be distributed in the cluster
typeset -F3 quotient="$diff/$cluster_lines"
# Adjust all sales value of current cluster (new sales value = origvalue + quotient)
echo "${SALES[*]}"|grep $cluster|while read line
do
item_id=`echo $line|awk -F"," '{print $1}'
old_sales_value=`echo $line|awk -F"," '{print $3}'
typeset -F3 new_sales_value="$old_sales_value + $ quotient"
SALES_TEMP=`echo "${SALES[*]}"|sed "s/$item_id,$cluster,$old_sales_value/$item_id,$cluster,$old_sales_value/g"`
SALES_TEMP=`echo "${SALES_TEMP[*]}"`
done
else
: # Do nothing as the total sales is less than 100 or greater then 200
fi
done
# Replace Sales File based on minimum functionality
echo "${SALES[*]}" > $2
}
Analysis:
total_sales of CLUSTER A 165 = 85 + 80
cluster_lines of CLUSTER_A = 2
diff 35 = 200 - 165
quotient=17.5 ($diff/$cluster_lines) # Distribute 17.5 to all ITEMS in CLUSTER_A
Original value of ITEM1 in CLUSTER A = 80, Changed to 97.5
Original value of ITEM3 in CLUSTER A = 85, Changed to 102.5
The difference needs to be distributed based on the # of lines of CLUSTER_A
Last edited by Scrutinizer; 11-27-2012 at 10:39 AM..
Reason: code tags
Hi All,
Kindly help on the below issue ASAP. Its very urgent.
I have script in which we have below two lines for code and it is not working. Please help.
files_to_process="
abc_*.log
def_*.log
ghi_*.log
"
typeset -A dir_list ${files_to_process}
the script is failing in Linux... (3 Replies)
Hello all. This is my first post/question on this site.
I’m a new Systems Analyst with previous experience with BASH. Although now I'm using AIX, and I’m trying to get a feel for the Korn shell (for those of you that don’t know AIX only uses the KORN shell).
I hope I put this into the correct... (10 Replies)
Hi,
Consider the code snippet below:
fun()
{
while read x
do
echo $x
done < somefile_that_does_not_exists
}
fun
echo I am here
Korn shell on HPUX prints the message "I am here", while the behaviour is different on AIX korn shell. We do not get the message on AIX. Any... (5 Replies)
Hi all,
Can someone point me in the right direction for a manual on the various statement options for 'if'. Basically I have a piece of code which says:
if ]
and I wondered what the -f was. I know the '!' means not equal..
As usual any help much appreciated.. (5 Replies)
Hi All
I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell.
Some operations like calculation don't work :
cat ${file1} | tail -$((${num1}-${num2})) > ${file2}
Is it possible to activate Korn Shell... (3 Replies)
In a Korn shell script I have,
cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt
The header is short
{{Company flag1}}
But the result in header.txt is
{{Company $cnumb}}
The value of $cnumb is 120. I am trying to get the value of $cnumb into the header.
I have tried /'$cnumb'/g,... (10 Replies)
Ho do I find out the verion of the Kron shell on my client`s system ?
There is no one to ask. They are not knowledged enough (hard to believe but yes).
Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
For e.g I have a file named "relation" which has three coloums i.e
JOHN MARY JACK
PETE ALISIA JONNY
TONY JACKIE VICTOR
If I do
grep -w 'JOHN' relation | awk '{print""$1" is husband of "$2" & father of "$3""}'
It gives out
JOHN i husband of MARY & father of JACK (which is desired... (7 Replies)
well i have this code here..and it works fine in kornshell..
#!/bin/ksh
home=c:/..../
input=$1
sed '1,3d' $input > $1.out
line=""
cat $1.out | while read a
do
line="$line $a"
done
echo $line > $1
rm $1.out
however...now i want it just in normal sh mode..how to convert this?... (21 Replies)