08-31-2009
q's on file sort
I have a file below which has a list of users and roles with each row having unique combination of users and roles.
USER1 ROLE1
USER1 ROLE2
USER2
USER3 ROLE1
USER3 ROLE2
USER3 ROLE3
USER4 ROLE2
....
....
I am trying to create a script which sorts the above file to have all the roles in one line delimited by commas per user to look like below:
USER1 ROLE1,ROLE2
USER2
USER3 ROLE1,ROLE2,ROLE3
USER4 ROLE2
....
....
I was able to do this with the script below but when the input is very large it takes very long and takes up cpu usage so I was wondering if someone could tell me a faster way to achive this.
#!/bin/ksh
INPUT=$1
cut -d' ' -f1 $INPUT | sort -u > USER_LIST
while read USER
do
**** ROLES=$(echo "`grep $USER $INPUT | cut -d' ' -f2 | tr '\12' ','`" | sed -e
's/,$//g')
**** [[ $USER != $ROLES ]] && echo $USER $ROLES
**** [[ $USER = $ROLES ]] && echo $USER
done < USER_LIST
---------- Post updated at 12:34 PM ---------- Previous update was at 12:24 PM ----------
please ignore the astrix in the above script
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
i want to sort a file by column 2, 3, 10 and 4(in this order), can anybody help me? thanks a lot. (2 Replies)
Discussion started by: tao
2 Replies
2. Shell Programming and Scripting
Dear All,
Good day. Here i am facing some problem like below.
file contains
12345 0001 090112
14385 0001 090112
13255 0001 090112
11345 0001 090112
....
I want to sort ascending according to the first column. What will be the shell script. (4 Replies)
Discussion started by: saifurshaon
4 Replies
3. Shell Programming and Scripting
Hi,
I have a file with the list of RPMs in the following format
unix-abc-bin-1.27.1-006901
unix-abc-cfg-1.27.1-006901
unix-xyz-bin-1.27.1-006901
unix-abc-bin-1.27.2-006902
unix-xyz-bin-1.27.2-006902
unix-xyz-img-1.27.2-006902
I need the output as shown below
unix-abc-bin-1.27.2-006902... (4 Replies)
Discussion started by: learnerlearner
4 Replies
4. Shell Programming and Scripting
Hi to all.
I'm trying to sort this with the Unix command sort.
user1:12345678:3.5:2.5:8:1:2:3
user2:12345679:4.5:3.5:8:1:3:2
user3:12345687:5.5:2.5:6:1:3:2
user4:12345670:5.5:2.5:5:3:2:1
user5:12345671:2.5:5.5:7:2:3:1
I need to get this:
user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies
5. UNIX for Advanced & Expert Users
Hello all -
I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies
6. Shell Programming and Scripting
Need to sort a portion of a file in a Alphabetical Order.
Example : The user adam is not sorted and the user should get sorted. I don't want the complete file to get sorted.
Currently All_users.txt contains the following lines.
##############
# ARS USERS
##############
mike, Mike... (6 Replies)
Discussion started by: evrurs
6 Replies
7. Shell Programming and Scripting
Input file:
100%ABC2 3.44E-12 USA
A2M%H02579 0E0 UK
100%ABC2 5.34E-8 UK
100%ABC2 3.25E-12 USA
A2M%H02579 5E-45 UK
Output file:
100%ABC2 3.44E-12 USA
100%ABC2 3.25E-12 USA
100%ABC2 5.34E-8 UK
A2M%H02579 0E0 UK
A2M%H02579 5E-45 UK
Code try:
sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies
8. Shell Programming and Scripting
Hi Experts,
I have a filelist collected from another server , now want to sort the output using date/time stamp filed.
- Filed 6, 7,8 are showing the date/time/stamp.
Here is the input:
#----------------------------------------------------------------------
-rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies
9. AIX
as friends can only Sort this file with awk from low to high from position 3 to 9 bone this:
0003344
A70003344prueba1
A70003347prueba1
A70003345prueba1
A70003349prueba1
A70003343prueba1
A70003342prueba1 (4 Replies)
Discussion started by: tricampeon81
4 Replies
10. UNIX for Beginners Questions & Answers
I have a csv file as shown below,
xop_thy 80 avr_njk 50 str_nyu 60
avr_irt 70 str_nhj 60 avr_ngt 50
str_tgt 80 xop_nmg 50 xop_nth 40
cyv_gty 40 cop_thl 40 vir_tyk 80
vir_plo 20 vir_thk 40 ijk_yuc 70
cop_thy 70 ijk_yuc 80 irt_hgt 80
I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies
LEARN ABOUT CENTOS
audio_support
audio_support(7I) Ioctl Requests audio_support(7I)
NAME
audio_support - audio driver support routines and interface
SYNOPSIS
#include <sys/audio.h>
DESCRIPTION
The audio support module supports audio drivers that use the new audio driver architecture. It also provides a limited number of ioctl(2)
functions for application programmers.
DATA STRUCTURES
The following data structures are defined to manage the different audio device types and channels.
Device Types
The following enumeration lists a number of generic device types.
typedef enum {
UNDEFINED, AUDIO, AUDIOCTL, USER1, USER2, USER3
} audio_device_type_e;
Currently, the Solaris audio mixer implements only the AUDIO and AUDIOCTL audio device types. See the mixer(7I) manual page for details.
The USER1, USER2 and USER3 device types allow third parties to write audio personality modules of their own.
Channel Structure
This structure is used to get and set state information on individual channels.
struct audio_channel {
pid_t pid; /* application's process ID */
uint_t ch_number; /* device channel */
audio_device_type_e dev_type; /* device type */
uint_t info_size; /* size of channel's */
/* info structure */
void *info; /* channel state information */
;
typedef struct audio_channel audio_channel_t;
The ch_number must specify the specific channel number to get or set. When the ioctl() returns, the pid contains the process ID of the
process that has that channel open and dev_type will contain the device type. If pid is 0 (zero), then the channel is not open. The pointer
*info must point to a buffer large enough to hold whatever audio device-related state structure that may be returned. Currently, only the
audio_info_t structure is returned. See the audio(7I) and mixer(7I) man pages for more information.
IOCTLS
The audio support driver provides the following ioctls():
AUDIO_GET_CH_NUMBER This ioctl() returns the channel number pointed to by the file descriptor. It is returned in the integer
pointer of the ioctl() argument.
AUDIO_GET_CH_TYPE This ioctl() returns the type of channel the process has open. It is returned in the audio_device_type_e
enumeration pointer of the ioctl() argument.
AUDIO_GET_NUM_CHS This ioctl() returns the number of channels the device supports. It is returned in the integer pointer of
the ioctl() argument.
MACROS
The following macro can be used to initialize data structures. The established convention is that the state corresponding to a field set to
-1 will not be modified.
AUDIO_INIT(I, S)
Where I is a pointer to an info structure and S is the size of that structure.
The following code segment demonstrates how to use this macro:
audio_info_t info;
AUDIO_INIT(&info, sizeof(info));
info.play.port = AUDIO_HEADPHONE;
err = ioctl(audio_fd, AUDIO_SETINFO, &info);
ERRORS
EINVAL The ioctl() is invalid for this file descriptor. The audio_channel_t structure's info pointer does not point to a buffer,
or the ch_number is bad.
ENOMEM The ioctl() failed due to lack of memory.
FILES
/usr/share/audio/samples
Audio sample files
ATTRIBUTES
See attributes(5) for a description of the following attributes:
+-----------------------------+------------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Architecture |SPARC, x86 |
|Availability |SUNWaudd, SUNWauddx, SUNWaudh |
|Stability Level |Evolving |
+-----------------------------+------------------------------+
SEE ALSO
ioctl(2), attributes(5), audio(7I), mixer(7I), streamio(7I)
FUTURE DIRECTIONS
Over time, additional audio personality modules will be added. Audio application programmers are encouraged to review this man page with
each Solaris release for new audio personality modules.
SunOS 5.10 2 January 2002 audio_support(7I)