Sponsored Content
Top Forums Shell Programming and Scripting How to group the output of a loop Post 302334150 by alvingo on Wednesday 15th of July 2009 02:12:58 AM
Old 07-15-2009
Question How to group the output of a loop

Hi Guys,

This is based on my question previously posted. Smilie

I have my shell script like this:

Code:
#!/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. Smilie

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 Smilie

Thanx in advance Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can I better group my output?

I have a script that puts out a list that looks like this: bb1 newyork bb1 pittsburg bb2 seattle bb2 spokane sl1 sacramento I want to seperate the output so that it instead has a space between each group so like this: bb1 newyork bb1 pittsburg bb2 seattle bb2 spokane sl1... (8 Replies)
Discussion started by: llsmr777
8 Replies

2. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies

3. UNIX Desktop Questions & Answers

Loop column output

I need help in what to do with a bash script? I'm trying to run a command to output the data from a table and then insert it into commands. Looping for each row of data. For example the output data from a table: 10 John house 20 Jane apt 30 Joe townhomeThen I need to take the output... (1 Reply)
Discussion started by: handband2
1 Replies

4. UNIX for Dummies Questions & Answers

output of file from several machines written to network share, then emailed to group.

I have a script on all the machines on my network that lists how many updates are available for each machine, and then outputs the answer to a file called updates.txt the output shows the hostname and the number of updates, like: computer_A 7 I want all these machines to output the data to... (1 Reply)
Discussion started by: glev2005
1 Replies

5. Shell Programming and Scripting

Group the output of the variable

Hi Guys, First time in scripting & first time here...:D I need help in this situation - My requirements is: I have a list e.g. list=`echo ls -l *` OR list=`sql.... select emp_id from employee ...` The Input is: ls -l OR emp_id A 4567 B 2231 C ... (2 Replies)
Discussion started by: alvingo
2 Replies

6. Shell Programming and Scripting

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"... (0 Replies)
Discussion started by: alvingo
0 Replies

7. Shell Programming and Scripting

ID - output group-memberships one per line

Hello, I am currently a little bit lost with my new shell-script. I am trying to output the results of the "id"-command as a "one per line" statement. For example: I have the user "test" with the group-memberships "group1, group2, group3". When I enter "id test" it will show me the output... (2 Replies)
Discussion started by: henryford
2 Replies

8. Shell Programming and Scripting

while loop output

:wall:Hi I am a beginner to unix In a shell script i see the below code # set admin email so that you can get email ADMIN=someone@somewhere.com host=`hostname` date=`date` # set alert level 70% is default ALERT=70 df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print... (1 Reply)
Discussion started by: prabhu_kumar
1 Replies

9. Shell Programming and Scripting

Need to create an for loop for adding an disk in veritas volume group.

Hi Experts I need an script to add an disk in to the veritas volume manager disk group. For example: # cd /tmp # view disk c6t5d2 c6t2d1 c6t3d7 c6t11d2 c7t11d2 c6t11d6 Normally we add the disk like this: # vxdg -g freedg freedisk01=c6t5d2 # vxdg -g freedg freedisk02=c6t2d1 #... (3 Replies)
Discussion started by: indrajit_preet
3 Replies

10. Shell Programming and Scripting

Summing per group in a loop

I want to sum and average all other columns by first column GR1 1 4 7 GR1 2 5 8 GR1 3 6 9 GR2 11 14 17 GR2 13 16 19 GR3 1 3 5 GR3 2 4 6 For a limited number of columns I can do... (2 Replies)
Discussion started by: jianp83
2 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 02:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy