Sponsored Content
Full Discussion: Sort, group rows
Top Forums Shell Programming and Scripting Sort, group rows Post 302273924 by patrykxes on Tuesday 6th of January 2009 08:04:59 AM
Old 01-06-2009
Hi

Source report:

User1,admin,rep,User2,shell,path1,x1,r1
User2,admin,rep,User7,shell,path1,x1,r1
User3,admin,rep,User4,shell,path1,x1,r1
User4,admin,rep,User3,shell,path1,x1,r1
User5,admin,rep,User1,shell,path1,x1,r1
User6,admin,rep,User5,shell,path1,x1,r1
User7,admin,rep,User6,shell,path1,x1,r1
User8,admin,rep,,,path1,x1,r1
User9,admin,rep,,,path1,x1,r1
User10,admin,rep,,,path1,x1,r1
User11,admin,rep,,,path1,x1,r1
...

I'd like to assign user names with numbers User2,User7,User4,User3,User1... from the fourth column to the same users from the first column, so as to obtain the following report:

User1,admin,rep,User1,shell,path1,x1,r1
User2,admin,rep,User2,shell,path1,x1,r1
User3,admin,rep,User3,shell,path1,x1,r1
User4,admin,rep,User4,shell,path1,x1,r1
User5,admin,rep,User5,shell,path1,x1,r1
User6,admin,rep,User6,shell,path1,x1,r1
User7,admin,rep,User7,shell,path1,x1,r1
User8,admin,rep,,,path1,x1,r1
User9,admin,rep,,,path1,x1,r1
User10,admin,rep,,,path1,x1,r1
User11,admin,rep,,,path1,x1,r1
...

ps.
only users User2,User7,User4,User3,User1... from the fourth column have shell
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort cmd to get GROUP BY?

Is there any way using the sort command to get something like a GROUP BY clause? I'm trying to sort through race_event records and group them by those individuals that raced together in the same race on the same date at the same track, but i run into a problem when there were days when the track... (6 Replies)
Discussion started by: RacerX
6 Replies

2. Shell Programming and Scripting

Sort the multi column rows

abc xyz - - - - - - - - - - - How to sort the second column in ascending order. (2 Replies)
Discussion started by: sandy1028
2 Replies

3. Shell Programming and Scripting

Convert rows to columns group

Hi I have the input file following like this "AIX" "AIX 6.0" "AIX 7.0" "Redhat 8" "Redhat 9" "Redhat 5.0 Enterprise Linux" "Sun Solaris 9" "Sun Solaris 10", "Sun Microsystems" "Oracle" .................................Like this 2000 lines I need to convert this input into... (5 Replies)
Discussion started by: selvanraj
5 Replies

4. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

5. Shell Programming and Scripting

Sort Data by Group !

Hello, I have a file and i want to sort by third column and extract the three top lines of each group, it is determined by the second column (144, 89, 55, etc). Could you please help me with the appropiate awk shell script XLY-XLP 144 0.592772 XLY-XLE 144 0.798121 ... (3 Replies)
Discussion started by: csierra
3 Replies

6. Shell Programming and Scripting

Awk: group rows by id and simple conversion

Hi all, I am a newbie to awk and trying to learn by doing examples. I got stuck at this relatively simple conversion. The start file looks like: 1 2 "t1" 1 3 "h1" 2 1 "h1" 2 2 "h2" and I want to convert it into 1 t1:2, h1:3; 2 h1:1, h2:2; Thanks. (9 Replies)
Discussion started by: eagle_fly
9 Replies

7. UNIX for Dummies Questions & Answers

Converting Columns To Rows Sort Of

Hi I'm a UNIX awk and sed novice at best. I'm trying to creat a .csv file so it can be graphed in Excel. Tried various xargs, awk, sed and paste but just can't seem to get the data to line up. Not sure if this is beyond for a question in these forums. Any help would greatly be appreciated. Have... (4 Replies)
Discussion started by: jimmyf
4 Replies

8. Shell Programming and Scripting

Group by and translate rows to column

I've a comma separated file with data below: 61401370587,505,1;0402686146,123;2387936.0;20170812 61401370587,505,2;0401296221,34;3.0;20170811 61401370587,505,5;0431169322,123;2387936.0;20170812 My requirement is to group by using 1st,2nd column . And translate the 3rd column's row data... (1 Reply)
Discussion started by: bhagat-reena
1 Replies

9. Shell Programming and Scripting

Rearrange rows by group pairs

Hello gurus, I have two variable columns 1 and 2 , and their respective groups in 3 and 4 var1 var2 gr1 gr2 a b g h c d h g d f d h f g h g d r h d p q a b h y h g r t g h I want to rearrange the rows in such a way that all similarly grouped (var1 var2) pairs are together . The... (4 Replies)
Discussion started by: senhia83
4 Replies

10. Shell Programming and Scripting

Sort by id value in every two rows

Hello, I am running ubuntu 14.04. My purpose is to sort below file according to value of id even though it contains alphanumeric strings inside double quote. File is not tab separated. I am not sure that can be done... mydata #INFO id="133 texas" logo="http://tx.yy.zz http://11.22.48 #INFO... (3 Replies)
Discussion started by: baris35
3 Replies
link(2) 							System Calls Manual							   link(2)

NAME
link() - link to a file SYNOPSIS
DESCRIPTION
The system call creates a new link (directory entry) for the existing file. path1 points to a path name naming an existing file. path2 points to a path name naming the new directory entry to be created. RETURN VALUE
Upon successful completion, returns zero. Otherwise, it returns -1 and sets (see errno(2)) to indicate the error. ERRORS
The system call fails and no link is created if one or more of the following is true: A component of either path prefix denies search permission. The requested link requires writing in a directory that does not permit writing. The user's or group's disk quota block limit has been reached for this file system. The link named by path2 exists. path points outside the allocated address space of the process. The reliable detection of this error is implementation dependent. Too many symbolic links were encountered in translating either path name. The maximum number of links to a file would be exceeded. Either the specified path exceeds bytes, or a component of either specified path exceeds while is in effect. The file named by path1 does not exist. A component of either path prefix does not exist. path2 points to a null path name. path1 or path2 is null. The directory to contain the file cannot be extended. A component of either path prefix is not a directory. The file named by path1 is a directory and the effective user ID is not a user who has appropriate privileges. Some file systems return this error whenever path1 names a directory, regardless of the user ID. The requested link requires writing in a directory on a read-only file system. The link named by path2 and the file named by path1 are on different logical devices (file systems). SEE ALSO
cp(1), link(1M), symlink(2), unlink(2), symlink(4), privileges(5). STANDARDS CONFORMANCE
link(2)
All times are GMT -4. The time now is 05:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy