How to group the output of a loop

Hi Guys,

This is based on my question previously posted. :slight_smile:

I have my shell script like this:

#!/usr/bin/sh
e_id=`sqlplus -s scott/tiger@DB<<eof
            SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF;
            select emp_id from employee;
            quit
            `
echo "Employee ID's $e_id"

group=GROUP1
# Getting the sss_no for each emp_id

for i in $e_id 
 do
   sss_nos=`sqlplus -s scott/tiger@DB <<eof
          SET PAGES 0 LINES 500 HEAD OFF;
          select sss_no from employee_bank where emp_id = $i;
          quit
          `
   echo "List of SSS no's $sss_nos"
   # Run a customize program that calls the sss_nos
   # SSS_move
   SSS_move $sss_nos $group
  sleep 2
done

The Output:
Employee ID's
4567
2231
1121
2233
4554
3243
1231
3311

List of SSS no's
45566
59589
55170
51530
33099
20234
87231
54192

SSS_move:
SSS_move 45566 GROUP1
SSS_move 59589 GROUP1
SSS_move 55170 GROUP1
SSS_move 51530 GROUP1
SSS_move 33099 GROUP1
SSS_move 20234 GROUP1
SSS_move 87231 GROUP1
SSS_move 54192 GROUP1

Now, how will I able to group the output of the loop so that I can assign GROUP1 only to the 1st two output of the loop then assign GROUP2 to the 2nd two output of the loop & so on. :confused:

Desired Output:
SSS_move 45566 GROUP1
SSS_move 59589 GROUP1
SSS_move 55170 GROUP2
SSS_move 51530 GROUP2
SSS_move 33099 GROUP3
SSS_move 20234 GROUP3
SSS_move 87231 GROUP4
SSS_move 54192 GROUP4

Also, how do I count the $sss_nos output so that I have this condition:
If my $sss_nos -gt 7 (w/c in my example above it is true) then assign to multiple GROUP#. If it is -lt 7 then group it only to GROUP1

Pls. help :smiley:

Thanx in advance :slight_smile:

Try this...

awk 'BEGIN { NR =1 } {print "SSS_move " $1 " GROUP - " int(NR / 2) }' <Your output File>