Sponsored Content
Top Forums Shell Programming and Scripting Create a script which sorts a file Post 302349018 by stevefox on Sunday 30th of August 2009 11:21:28 PM
Old 08-31-2009
Create a script which sorts a file

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.


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


Last edited by Neo; 08-31-2009 at 04:47 AM.. Reason: code tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create file in script

I am trying to create a new file(string) with todays date in a backup folder string= `date '+%d%m%y'` find * * * /home/SMB-2000/* -print |cpio -ovm > /home/bkups/$string After excecuting I get the messege # ./b2 ... (3 Replies)
Discussion started by: paparazi
3 Replies

2. Shell Programming and Scripting

create file in script

hi i am reading a directory, and reading those files one by one i need to write some of file contents to a new file ,for this i need to create a new file for each file please tell me how to create new file in shell script thanks Satya (4 Replies)
Discussion started by: Satyak
4 Replies

3. Shell Programming and Scripting

Create a file from within a script

Hi, I want to create a file from within a script that checks whether the file itself exists or not. Like: if ] then echo Creating file... cat << EOF > .theFile echo This line should be in the file EOF fi If I run the script with no condition (commenting... (2 Replies)
Discussion started by: lamano
2 Replies

4. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

5. Shell Programming and Scripting

Script that sorts and show only unique IP

Hi, I have this data: Jun 16 88.191.117.191 = 100 Jun 16 88.191.117.191 = 70 Jun 16 88.191.117.191 = 30 Jun 16 200.242.67.142 = 65 Jun 16 125.77.107.212 = 40 Jun 16 125.77.107.212 = 60 And I want to have the ff ouput: Jun 16 88.191.117.191 = 200 Jun 16 ... (6 Replies)
Discussion started by: linuxgeek
6 Replies

6. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

7. Shell Programming and Scripting

Create a file with comment in script

Hello, Be indulgent for my english. Can you help me ? function f1 { } egrep -v '^#' list_file \ | while read arg1 arg2 arg3 arg4; do f1 $arg1 $arg2 $arg3 $arg4 done In list_file there is I want to replace list_file by a $var then when i launch the script with a file's... (13 Replies)
Discussion started by: amazigh42
13 Replies

8. Shell Programming and Scripting

Can't create file in CGI Script

Hi I have some simple script within the context of a cgi script that create a file to write to. If I run the script from the command line as root the file is created with no issue. However when I run the script from a web page with the apache account, it dies. The code lines are: sub... (3 Replies)
Discussion started by: larryjmoon
3 Replies

9. Shell Programming and Scripting

Script to create a CSV file

I created a script that will go out and so a "/sbin/chkconfig --list | egrep XXX" against a server list that would create an output file like the following example: ---------------------------------------------------------------------------------- SERVER1 RC_Script_1 0:off 1:off 2:off... (4 Replies)
Discussion started by: asnatlas
4 Replies

10. AIX

Poll of sorts - on LDAP

1) Do you use LDAP on AIX? (as a client) 2) If yes, what LDAP server technology do you use: a) IDS (or ITDS) - IBM Tivoli Directory Server b) AD c) openLDAP d) other - please list. I ask, because I am looking at openLDAP as well as IDS and am wondering if there is a clear preference I... (4 Replies)
Discussion started by: MichaelFelt
4 Replies
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)
All times are GMT -4. The time now is 09:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy