Operating System - HP-UX
1828662 Members
1463 Online
109983 Solutions
New Discussion

How to group the output w/ limit

 
Alvin Ramos
Occasional Contributor

How to group the output w/ limit

Hi All,

Second time to post on this group :)

I'm pulling my hair now 'coz I'm so dumb to produce this requirement.

Requirement: I want to run a utility by limiting the no. inside my process (mov##) to be able to use in multi streaming.

Here is my script:
--Input: "user_list.txt"
40013163:5
40109925:3
89877423:4
73084042:1
40152547:2
82475674:0

--Script:
set -A ext_ids `cat user_list.txt`

process_id=2
total_extid=${#ext_ids[@]}
cnt=0
while [ $cnt -lt $total_extid ]
do
if [ $total_extid -lt 6 ]
then
echo "PREQ_MOVER mov0$process_id ${ext_ids[$cnt]} "
else
# Always starts w/ process_id 2
process_id=`expr 2 + $cnt / 3` # Increase the dividend to increase the process_id value
if [ $process_id -le 9 ]
then
processid="0$process_id"
else
processid=$process_id
fi
extids=`echo "${ext_ids[$cnt]}"|cut -d : -f 1`
echo "PREQ_MOVER mov$processid $extids "
count=`echo "${ext_ids[$cnt]}"|cut -d : -f 2`
## Un/Comment here
#if [ $count -eq 0 ]
# then
# count=$(($count + 1))
#fi
fi
## Un/Comment here
#cnt=$(($cnt + $count))
cnt=$(($cnt + 1))
done
# Single stream or multi stream
if [ $total_extid -lt 6 ]
then
echo "\n\tRunning Single Stream of MOVER\n"
echo "MOVER mov0$process_id SOURCE_DB"
else
echo "\n\tRunning Multiple Stream of MOVER\n"
proc=2
while [ $proc -le $process_id ]
do
if [ $proc -le 9 ]
then
procs="0$proc"
else
procs=$proc
fi
echo "MOVER mov${procs} "
proc=$(($proc + 1))
done
fi

Output:
PREQ_MOVER mov02 40013163
PREQ_MOVER mov02 40109925
PREQ_MOVER mov02 89877423
PREQ_MOVER mov03 73084042
PREQ_MOVER mov03 40152547
PREQ_MOVER mov03 82475674

Running Multiple Stream of MOVER

MOVER mov02
MOVER mov03

Now by editing the script by uncommenting the commented fields. I get...
Output:
PREQ_MOVER mov02 40013163
PREQ_MOVER mov03 82475674

Running Multiple Stream of MOVER

MOVER mov02
MOVER mov03
Note: The output above skips from 40013163 to 40013163 & the rest are not shown.

Desired Output: (limit to 3 accounts inside each mov## process)
PREQ_MOVER mov02 40013163 -> since it has 5, it will take up the whole process "mov02". This will fill up the process even if it exceeds the limit
PREQ_MOVER mov03 40109925 -> will take mov03 as it has 3
PREQ_MOVER mov04 89877423 -> will take mov04 as it has 4. This will fill up the process even if it exceeds the limit.
PREQ_MOVER mov05 73084042 -> has 1, will use mov05 since the limit is not met
PREQ_MOVER mov05 40152547 -> has 2, will still use mov05 to fill up the limit
PREQ_MOVER mov06 82475674 -> this will use mov06 as mov05 is already filled up.

Running Multiple Stream of MOVER

MOVER mov02
MOVER mov03
MOVER mov04
MOVER mov05
MOVER mov06

Question: How to be able to display the desired output in order to limit the nos of each mov## process (even it exceeds) in sequence (no skipping).

Purpose: To run the utility MOVER in multiple stream by not skipping a user in the list.

I hope the explanation above is sufficient & I hope someone will enlighten me on this.

Hoping for your kind assistant.

Thanx
2 REPLIES 2
OldSchool
Honored Contributor

Re: How to group the output w/ limit

1) 40013163:5
2) 40109925:3
3) 89877423:4
4) 73084042:1
5) 40152547:2
6) 82475674:0

so the requirement can be stated as combine lines up to a maximum of 3, (lines 4 and 5), but more than 3 are permitted if the come from one source line (lines 1 and 3)? What do you do w/ line 6, which is 0?
Dennis Handly
Acclaimed Contributor

Re: How to group the output w/ limit

(If you have scripts with indentation, you should select the "retain format" box, or attach a file.)

For the second block, did you want to uncomment one line and comment the next?
## Un/Comment here
(( cnt = cnt + count ))
#(( cnt = cnt + 1 ))

>How to be able to display the desired output in order to limit the # of each mov## process (even it exceeds) in sequence (no skipping).

Your basic problem is that you are using cnt to index though your array and do computations for your process_id. You then increment cnt and skip the entries at the end of your array.

You might want to make your script more C-like but not scummy C shell:
set -A ext_ids $(< user_list.txt)
typeset -Z2 process_id proc
total_extid=${#ext_ids[@]}
(( process_id = 2 )) # Always starts with process_id 2
(( usage = 0 ))
(( capacity = 3 ))
(( cnt = 0 ))
while (( cnt < total_extid )); do
if (( $total_extid < 6 )); then
echo "PREQ_MOVER mov$process_id ${ext_ids[$cnt]}"
(( count = capacity ))
else
extids=$(echo "${ext_ids[$cnt]}" | cut -d : -f 1)
count=$(echo "${ext_ids[$cnt]}" | cut -d : -f 2)
echo "PREQ_MOVER mov$process_id $extids"
if [ $count -eq 0 ]; then
(( count = 1 ))
fi
fi
if (( usage + count < capacity )); then
(( usage += count ))
else
(( process_id += 1 ))
(( usage = 0 ))
fi
(( cnt += 1 ))
done

# Single stream or multi stream
if (( total_extid < 6 )); then
echo "\tRunning Single Stream of MOVER\n"
echo "MOVER mov$process_id SOURCE_DB"
else
echo "\tRunning Multiple Stream of MOVER\n"
(( proc=2 ))
while (( proc <= process_id )); do
echo "MOVER mov${proc}"
(( proc += 1 ))
done
fi