Sponsored Content
Top Forums UNIX for Beginners Questions & Answers HELP on 'sectional' or 'group' sorting Post 303016902 by newbie_01 on Saturday 5th of May 2018 11:44:23 PM
Old 05-06-2018
HELP on 'sectional' or 'group' sorting

Hi,

I need to do some section/group sorting. At the moment, I get around it by grep group by group and then re-directing to the same 'final' output file.

Below is what's been sorted so far based on the second field

Code:
$ awk -F"," '{ { print $5 " == " $6 } }' /tmp/x.csv | grep -v "^env" | grep -v "^ " | grep -v "^$" | awk -F"." '{ print $1 }' | sort | uniq -c | sort -k2
     22 DEVELOPMENT == 10
     54 DEVELOPMENT == 11
     10 DEVELOPMENT == 12
     11 DEVELOPMENT == 8
      4 DEVELOPMENT == 9
     43 PRODUCTION == 10
     87 PRODUCTION == 11
     15 PRODUCTION == 12
     14 PRODUCTION == 8
      5 PRODUCTION == 9
     47 QUAL == 10
     92 QUAL == 11
     16 QUAL == 12
     11 QUAL == 8
      5 QUAL == 9
     35 TEST == 10
     96 TEST == 11
     15 TEST == 12
     15 TEST == 8
      4 TEST == 9

I want to sort the above so that the output will be as below. Let's refer to this as the final output. final.txt file.

Code:
     10 DEVELOPMENT == 12
     54 DEVELOPMENT == 11
     22 DEVELOPMENT == 10
      4 DEVELOPMENT == 9
     11 DEVELOPMENT == 8
     15 PRODUCTION == 12
     87 PRODUCTION == 11
     43 PRODUCTION == 10
      5 PRODUCTION == 9
     14 PRODUCTION == 8
     16 QUAL == 12
     92 QUAL == 11
     47 QUAL == 10
      5 QUAL == 9
     11 QUAL == 8
     15 TEST == 12
     96 TEST == 11
     35 TEST == 10
      4 TEST == 9
     15 TEST == 8

Because I don't know how to produce the final output using awk or sort. What I did instead is run several of the commands below, grepping for the string DEVELOPMENT, PRODUCTION and so on

Code:
$ awk -F"," '{ { print $5 " == " $6 } }' /tmp/x.csv | grep -v "^env" | grep -v "^ " | grep -v "^$" | awk -F"." '{ print $1 }' | sort 
| uniq -c | sort -k2 | grep "DEVELOPMENT" >> final.txt

Perhaps someone know a trick or too on how to do it a lot better. I don't see how using sort only will be able to do this. Advise much appreciated. Thanks.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge group numbers and add a column containing group names

I have a file in the following format. Groups of data merge together and the group number is indicated above each group. 1 adrf dfgr dfg 2 dfgr dfgr 3 dfef dfr fd 4 fgrt fgr fgg 5 fgrt fgr (3 Replies)
Discussion started by: Lucky Ali
3 Replies

2. Shell Programming and Scripting

Merge group numbers and add a column containing group names

Hi All I do have a file like this with 6 columns. Groups of data merge together and the group number is indicated above each group. 1 1 12 26 289 3.2e-027 GCGTATGGCGGC 2 12 26 215 6.7e+006 TTCCACCTTTTG 3 9 26 175 ... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

3. Shell Programming and Scripting

sort multipath sectional data

Hi all, I'm running a command on an ESXi server and the output for multipath device info is not in order. Can any of you SED or AWK gurus show me how I might sort the sectional data where both LUN paths are in order? Output: ... (3 Replies)
Discussion started by: stovie1000
3 Replies

4. Shell Programming and Scripting

Group on the basis of common text in the square bracket and sorting

File A 99 >ac >ss >juk 70 >acb >defa 90 >ca 100 >aa >abc >bca 85 >cde 81 >ghi >ghij 87 >def >fgh <ijk 89 >fck >ghij >kill >aa The given output shud be 100 >aa >abc >bca 87 >def >fgh <ijk 89 >fck >ghij >kill >aa (2 Replies)
Discussion started by: cdfd123
2 Replies

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

6. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

7. Shell Programming and Scripting

Sorting group information for accounts

I have an input file that contains the primary and secondary groups a user should have based on a pre-defined role. The input file looks like this: <user_login>|<comment_field>|<role> After I execute my script to do some grepping I have the following user file where the secondary groups are... (10 Replies)
Discussion started by: MaindotC
10 Replies

8. Shell Programming and Scripting

Sorting group of records and loading last record

Hi Everyone, I have below record set. File is fixed widht file 101newjersyus 20150110 101nboston us 20150103 102boston us 20140106 102boston us 20140103 I need to group record based on first 3 letters in our case(101 and 102) and sort last 8 digit in ascending order and print only... (4 Replies)
Discussion started by: patricjemmy6
4 Replies

9. Programming

Sql ORA-00937: not a single-group group function

I'm trying to return only one row with the highest value for PCT_MAX_USED. Any suggestions? When I add this code, I get the ORA-00937 error. trunc(max(decode( kbytes_max, 0, 0, (kbytes_alloc/kbytes_max)*100))) pct_max_used This is the original and returns all rows. select (select... (3 Replies)
Discussion started by: progkcp
3 Replies
remove group(1m)														  remove group(1m)

NAME
remove group - Removes all group members and the group from the specified name service entry SYNOPSIS
rpccp remove group group-entry-name [-s syntax] OPTIONS
Indicates the name syntax of the entry name (optional). The only value for this option is the dce name syntax, which is the default name syntax. Until an alternative name syntax becomes available, specifying the -s option is unnecessary. ARGUMENTS
Indicates the name of the target group. For an entry in the local cell, you can omit the cell name and specify only the cell-relative name. DESCRIPTION
The remove group command removes a group from the name service database. The group need not be empty. The entry name of the group is required. Privilege Required You need write permission to the CDS object entry (the target group entry). NOTE
This command is replaced at Revision 1.1 by the dcecp command and may not be provided in future releases of DCE. EXAMPLES
The following commands run RPCCP and remove the group from the name service entry /.:/LandS/anthro/Calendar_group: $ rpccp rpccp> remove group /.:/LandS/anthro/Calendar_group RELATED INFORMATION
Commands: add member(1m), remove member(1m), show group(1m) remove group(1m)
All times are GMT -4. The time now is 08:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy