Sponsored Content
Full Discussion: Sort question
Top Forums UNIX for Beginners Questions & Answers Sort question Post 302992921 by jimmyf on Friday 3rd of March 2017 01:14:22 PM
Old 03-03-2017
Sort question

Have a text file containing 4 columns, the 4th column is sorted numerically in descending order. The 2nd column is alpha text. Been able to get the 4th column to sort in descending order. The 2nd column sorts correctly but it's also in reverse. Would like to be able to keep the 4th column sort numerically descending while the 2nd column is sorted a-z, not z-a. This is what I have and can't seem to get it to work because everything is reversed.
Code:
sort -k2 -k4 -r file

this is what I'm trying to get:
Code:
xxxx apples xxxx 100
xxxx apples xxxx 90
xxxx oranges xxxx 80
xxxx oranges xxxx 70
xxxx pears xxxx 100
xxxx pears xxxx 90

this is what I'm getting because everything is reversed:
Code:
xxxx pears xxxx 100
xxxx pears xxxx 90
xxxx oranges xxxx 80
xxxx oranges xxxx 70
xxxx apples xxxx 100
xxxx apples xxxx 90

I'm sure this is simple but just can't get it to work.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort Question

M 47 HIS:LOT 32 DUTY 2 MIKE, FINISHED MIKE ACTIVE STATUS 23TASK YES GOOD 100TASK NO GOOD ======================================== M 47 HIS:LOT 1 DUTY 1 MIKE, FINISHED MIKE ACTIVE STATUS 23TASK YES GOOD ... (7 Replies)
Discussion started by: bobo
7 Replies

2. UNIX for Dummies Questions & Answers

Sort/Grep Question

Hello all, I have a test file that has the format: ..... O 3.694950 -.895050 1.480000 O 5.485050 .895050 1.480000 Ti -4.590000 4.590000 2.960000 Ti -2.295000 ... (5 Replies)
Discussion started by: aarondesk
5 Replies

3. UNIX for Dummies Questions & Answers

SORT question

I'm looking for a sort command that will sort by zip code first then by last name. (zip code is the last field, last name is first field) data file looks like this. Hope Bob 1234 Main ST. Colorado Springs, CO 80920 I was thinking along the lines of: sort -k9n address.data //for the... (2 Replies)
Discussion started by: ssgatbliss
2 Replies

4. UNIX for Dummies Questions & Answers

UNIX Sort question

I was trying to check for the sort of some columns (say 1-10) of particular file. Now, by default, the Unix sort uses as a separator whitespace (e.g. if you have 'foo bar' then it separates it into 'foo' and 'bar' to use as keys) Now, I know which particular columns I want to use as the sort... (1 Reply)
Discussion started by: rev.meister
1 Replies

5. Shell Programming and Scripting

sort question

Hi all. Is there a way that I can use the sort command too sort the following field by earliest time (12:00AM) to latest time (11:59PM)? 07:12PM 07:53PM 07:54PM 08:07PM 10:15AM 10:21AM TIA!!!!!! (1 Reply)
Discussion started by: lyoncc
1 Replies

6. Shell Programming and Scripting

sort question

Hi all. HPUX - posix shell - script question Here's my data: f1 f2 f3 f4 f5 f6 |02/12/09|12:33PM|3|Oceanview |OVT #1| VISA/MC |02/12/09|12:14PM|3|Oceanview |OVT #1| VISA/MC |02/12/09|09:13AM|4|Oceanview |OVT #1| VISA/MC ... (8 Replies)
Discussion started by: lyoncc
8 Replies

7. Shell Programming and Scripting

sort | uniq question

Hello, I have a large data file: 1234 8888 bbb 2745 8888 bbb 9489 8888 bbb 1234 8888 aaa 4838 8888 aaa 3977 8888 aaa I need to remove duplicate lines (where the first column is the duplicate). I have been using: sort file.txt | uniq -w4 > newfile.txt However, it seems to keep the... (11 Replies)
Discussion started by: palex
11 Replies

8. Shell Programming and Scripting

Sort question.

Hi Guys, I have a file to be sorted and uniq with the following format. S00001002|01|20021231 S00001002|01|20011031 S00001006|01|20120430 S00001006|01|20111231 S00001006|01|20111031 S00001006|01|20110831 S00001006|01|20110731 S00001006|01|20101231 S00001006|01|20091231... (5 Replies)
Discussion started by: nua7
5 Replies

9. UNIX for Dummies Questions & Answers

Sort command question

I have a file like this: /vol/eng_app_0103z /vol/eng_app_0103z /vol/eng_app_0120z /vol/eng_app_0126z /vol/eng_app_0144z /vol/eng_app_0150z /vol/eng_app_0154z /vol/eng_app_01551z /vol/eng_app_01552z /vol/eng_app_0155z /vol/eng_app_0164z /vol/eng_app_0199zWhen I use the sort command... (3 Replies)
Discussion started by: newbie2010
3 Replies

10. Shell Programming and Scripting

Sort command question

I have a question about what the sort command is doing. Here is some sample data: 348201310013RVE 2 600201310013GFJ 70 3302013020101NS 40 600201309013GFJ 70 The sort command that is running is as follows: sort -k 1,3 -k 12,4 input.txt > output.txt ... (6 Replies)
Discussion started by: Drenhead
6 Replies
sa(8)							      System Manager's Manual							     sa(8)

NAME
sa - Summarizes accounting records SYNOPSIS
sa [-abcdDfijkKlmnorstu] [-v Number] [-S SaveFile] [-U UserFile] [File] The sa command helps you manage the large volume of accounting information that is generated each day when system accounting has been enabled by the system administrator or by the superuser. FLAGS
Outputs all command names (including those containing unprintable characters and commands used only once) in the last column. In the default format, such commands are summed and the total is written as the entry ***other. Sorts cpu output column 3 according to the sum of user and system CPU time divided by the amount of CPU time required to execute the command entered in the last column (6) as many times as is entered in the first column (1). Adds three percentage columns to the default format to list percentages as follows: Lists the percent- age of the number of times each command was executed with respect to the total number of times all commands were executed (see 1a below). Lists the percentage of the amount of real time required to execute each command the number of times entered in the first column with respect to the total real time required to execute the total of all commands entered in the last column (see 2a below). Lists the percent- age of the amount of command CPU time required to execute each command the number of times entered in the first column with respect to the total CPU time required to execute the total of all commands entered in the last column (see 3a below). Sorts avio output column (4) in descending order according to the average number of disk I/O operations. Substitutes tio column (4a) for the avio (4) column and sorts tio output column 4a in descending order according to the total number of disk I/O operations. Used with the -v flag to inhibit interactive threshold comparison of commands. Reads raw database file /var/adm/pacct only. Does not include records from summary database file /var/adm/savacct. Outputs the average number of seconds per command in default columns 2, 3, and 4 instead of the total time in minutes for the number of calls entered in column 1 for each command. Sorts and outputs records according to the value in the k output column 5 in descending order. Substitutes k*sec column (5a) for the k (5) column and sorts the k*sec output column in descending order according to the value of the memory time integral. Separates cpu column 3 into two columns. The new column entries are column 3a, which lists the s (system) part of the CPU minutes, and column 3b, which lists the u (user) part of the CPU minutes. Outputs a 5-column file, which provides the information in the following table. Listed below in left-to-right order are the column identification suffixes, or none when no suffix is used, and the purpose of the column. Some columns are identical to the default output format described in the table in the DESCRIPTION section; these are marked with *. Username or user ID as written in the /etc/passwd file. The total number of processes executed by the user during the accounting period. Same as column 3 in the default output file. Same as column 4a in the default output file. Same as column 5a in the default output file. Outputs the default format sorted in descending order according to the number of times each command was called. Substitutes, in the default output format, the ratio of user CPU time (u) to system CPU time (s) as u/s in column 3 in place of the total user and system CPU time (cpu) for the number of calls entered in the first column. The default format, described under Description, is resorted in ascending order according to the values entered in column 3, cpu time. This sort is the reverse of the default sort. Merges information in accounting database file /var/adm/pacct with summary files you specify with the -U and -S flags, or merges the database file information with information in default files /var/adm/usracct or /var/adm/savacct. After the merge, database file /var/adm/pacct is truncated. The use of this flag also implies the use of the -a flag. Uses SaveFile as the command summary file in place of file /var/adm/savacct. Adds the re/cp column (3d) to the default format. Entries in this column express the ratio of real time to total (cpu) time, which is the sum of user and system time for each command entered in the last column. Suspends all other flags and prints the user numeric ID, the CPU time, memory usage, number of I/O operations, and the command name for each command. Uses UserFile as the user summary file in place of file /var/adm/usracct to record per-user statistics output with the -m flag. Prints, as a query, the name of each command used Number times or fewer to the standard output as follows: command-- where command-- is the name of the command written to the standard output by sa. When you respond by typing y to the standard input, the command record is omitted from a default-formatted list at the end of the interac- tive command queries written to the standard output. The columnar values of the omitted record are totaled in an added record whose command name is **junk** in the last column of that list. When you type any other character, the record for the queried command name remains in the default output list at the end of the interactive commands written to the standard input. DESCRIPTION
When you use the -s flag with the sa command, the information in /var/adm/pacct is condensed into summary file /var/adm/savacct, which con- tains a count of the number of times each command was called and the amount of time system resources were used. Condensed information for each user is stored in /var/adm/usracct. This condensed-information file conserves storage space because on a large system the /var/adm/pacct daily process file can grow by as many as 100 blocks per day. Summary files are normally read before accounting files are, so that files produced by sa include all available information. When a filename is given as the last argument, the named file is treated as the process accounting file. The /var/adm/pacct file is the default process accounting file. When the sa command is invoked with no flags, the default output summary is an unheaded 6-column file consisting of, in some cases, infor- mation having an identification suffix in the column. The identification suffix may be changed from the default (no flags specified) output format by using various flags. The following table lists the columns with left-to-right reference column numbers (not included in output) for the default format on the left, the identification suffix for the entry when one is used (or none when one is not in the middle), and the purpose of the information in that column on the right. Columns having more than one identification suffix description (2 and 2a, for example) use the alternate suffix designation in the same sa output printout column for each of the listed alternate entries for the column. For example, the second column has two possible suffix designations: re and %. The re reference in the middle column describes the information in the second column of the output printed by the sa command when this suffix is used. Correspondingly, the % reference describes the information in the sa output when the % suffix is used. 1 none The number of times the command entered in the last column (6) was called. 1a % When the -c flag is used, sa adds this column after column 1 to list the number of times the command was called (entered in column 1) as a percentage of the total number of times all commands entered in the last column were called. 2 re The number of real-time (elapsed) minutes required to execute the command entered in the last column (6) as many times as is entered in the first column (1). 2a % When the -c flag is used, sa also adds this column after col- umn 2 to list the amount of real time (entered in column 2) required to process the command entered in the last column (6) as many time as is entered in the first column (1), as a percentage of the total amount of real time required to process all of the commands listed in the last column. 3 cpu The number of CPU (user plus system) minutes used to execute the command entered in the last column (6) as many times as is entered in the first column (1). 3a u The number of user CPU minutes used. 3b s The number of system CPU minutes used. 3c u/s When the -o flag is used, substitutes u/s column (3c) for the cpu (3) column and sorts the u/s output column in descending order according to the ratio of user CPU time to system CPU time. 3d % When the -c flag is used, sa also adds this column after col- umn 3 to list the amount of CPU time (entered in column 3) required to process the command, entered in the last column, the number of times, entered in the first column, as a per- centage of the total CPU time required to process all of the commands listed in the last column. 3e re/cpu When the -t flag is used, adds the re/cpu column to the default output format. Entries in this column express the ratio of real CPU process time to total CPU time (cpu), which includes user and system time. These entries appear after entries for the cpu (3) column. The default output sort remains unchanged. 4 avio The average number of input/output operations for each listed command. 4a tio The total number of input/output operations for each listed command. 5 k The average number of kiloblocks (blocks x 1024) of memory used for each command process. 5a k*sec CPU storage-time integral in K-core seconds (seconds x 1024). 6 none The command name (a trailing * [asterisk] indicates a forked program). Other considerations for entries in the printed sa output are as follows: All times are expressed to nearest one hundredth. The default format is sorted in descending order according to the values entered in column 3, cpu time. You should not share accounting files among nodes in a distributed environment. Each node should have its own copy of the various accounting files. When you are also using /usr/sbin/acct/* accounting commands, do not delete accounting records in the /var/adm/pacct process accounting source file because these records also provide information for summary data files when the -s option is used. EXAMPLES
To summarize accounting records for all commands entered in the /var/adm/pacct process database file, enter: sa -a Commands used only once are summed with the entry ***other in the last column of the default output format. To summarize accounting records according to the average number of kiloblocks of memory used for each command, enter: sa -k FILES
Specifies the command path Process accounting database file. System process accounting summary file. User process accounting summary file. RELATED INFORMATION
Commands: acct(8), acctcms(8), acctcom(8), acctcon(8), acctmerg(8), acctprc(8), fwtmp(8), runacct(8) delim off sa(8)
All times are GMT -4. The time now is 07:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy