Group the output of the variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Group the output of the variable
# 1  
Old 07-14-2009
Bug Group the output of the variable

Hi Guys,

First time in scripting & first time here...Smilie
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 1121
D 2233
E 4554
F 3243
G 1231
H 3311

What I want the output would be:

if the output count of the list -gt 7 then group the list by 4 (group=4), if the output count is -lt 7 group the list by 2 (group=2)
A group1 4567 group1
B group1 2231 group1
C group2 1121 group2
D group2 2233 group2
E group3 4554 group3
F group3 3243 group3
G group4 1231 group4
H group4 3311 group4

I hope some gurus can help me on this.

Thanx a bunch in advance!!! SmilieSmilie
# 2  
Old 07-14-2009
whats the criteria for group 1/2 ? Please state your requirement clearly along with sample input/out in tags.
# 3  
Old 07-15-2009
re: Group the output of the variable

Input is:
ls -l
A
B
C
D
E
F
G
H
-OR-
emp_id
4567
2231
1121
2233
4554
3243
1231
3311

Output would be like:
Group the first 2 list to group 1, then group the 2nd 2 list to group2 upto group 4 if the count of the list is -gt 7.
Group the first 4 list to group 1, then group the 2nd 4 list to group2 if the count of the list is -lt 7.
Output in ls-l:
A group1
B group1
C group2
D group2
E group3
F group3
G group4
H group4
-OR-
Output in emp_id
4567 group1
2231 group1
1121 group2
2233 group2
4554 group3
3243 group3
1231 group4
3311 group4

Thanx Smilie

---------- Post updated 07-15-09 at 09:56 AM ---------- Previous update was 07-14-09 at 10:22 PM ----------

Hi Guys,

Anyone can help? Smilie

Regards

---------- Post updated at 02:15 PM ---------- Previous update was at 09:56 AM ----------

Hi Guys,

No need to reply on this one, instead see my new post.
############
############
https://www.unix.com/shell-programmin...#post302334150
############
############
It seems the question above is a bit confusing to all - so I post my script in the other post for better understanding.

Thanx
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. UNIX for Advanced & Expert Users

Group environment variable

Is it possible to set an environment variable or add something to the path for every user in a group? I guess I mean the equivelent of going into each member's profile and adding a directory to their path var, but without physically doing that for each of them. So just set it globally the... (4 Replies)
Discussion started by: steadyonabix
4 Replies

3. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

4. 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

5. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 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

How to group the output of a loop

Hi Guys, This is based on my question previously posted. :) 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 ... (1 Reply)
Discussion started by: alvingo
1 Replies

8. 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

9. 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

10. 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
Login or Register to Ask a Question