Sponsored Content
Full Discussion: sort on multiple keys
Top Forums UNIX for Advanced & Expert Users sort on multiple keys Post 302114188 by teqmem on Friday 13th of April 2007 01:05:47 AM
Old 04-13-2007
sort on multiple keys

Hello,

Say I have a file with plain text as shown below. Some columns may have multiple words (like "DESC 1", "DESC 1 2", "DESC 1 2 3"). Let's say the file below has 4 columns: 1st(AA), 2nd(BB), 3rd(DESC 1, ...), 4th(CC 1, ...).

Code:
1234567890123456789012345678901234567890
AA  BB   DESC 1 2 3          CC 1 2 2
AA  BB   DESC 1 2            CC 1 2
AA  BB   DESC 1              CC 1

I'd like to use the UNIX sort utility to sort based on these orders: 4th, 3rd, 2nd, then 1st.

How would I construct the key parameters (-k) to the sort utility?

Thank you.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Sort on two keys

Hello, I am trying to sort a text file by two keys but the second key should be reversed. I have tried -nt '|' -k 4 -rk 5 but it just sorts reversed on key 4. Does anyone have any suggestions ? Thanks (8 Replies)
Discussion started by: clarcombe
8 Replies

2. Shell Programming and Scripting

Sorting with multiple numeric keys

Data I want to sort :- 1 10 jj Y 2 100 vv B 19 5 jj A 1 11 hq D 3 8 op X 44 78 ds GG 1 8 hq D and want to sort based on the first 2 columns - which hold numeric values. Am using : cat filename | sort -nk 1,2 But the result is :- 1 10 jj Y 1 11 hq D (1 Reply)
Discussion started by: sinpeak
1 Replies

3. UNIX for Dummies Questions & Answers

Joining files based on multiple keys

I need a script (perl or awk..anything is fine) to join 3 files based on three key columns. The no of non-key columns can vary in each file. The columns are delimited by semicolon. For example, File1 Dim1;Dim2;Dim3;Fact1;Fact2;Fact3;Fact4;Fact5 ---- data delimited by semicolon --- ... (1 Reply)
Discussion started by: Sebben
1 Replies

4. Shell Programming and Scripting

Sum a column value based on multiple keys

Hi, I have below as i/p file: 5ABC 36488989 K 000010000ASB BYTRES 5PQR 45757754 K 000200005KPC HGTRET 5ABC 36488989 K 000045000ASB HGTRET 5GTH 36488989 K 000200200ASB BYTRES 5FTU ... (2 Replies)
Discussion started by: nirnkv
2 Replies

5. Shell Programming and Scripting

Sorting problem: Multiple delimiters, multiple keys

Hello If you wanted to sort a .csv file that was filled with lines like this: <Ticker>,<Date as YYYYMMDD>,<Time as H:M:S>,<Volume>,<Corr> (H : , M, S: ) by date, does anybody know of a better solution than to turn the 3rd and 4th colons of every line into commas, sorting on four keys,... (20 Replies)
Discussion started by: Ryan.
20 Replies

6. Shell Programming and Scripting

[SOLVED] Sort on multiple keys

Can you guys pls take a look at this. I need to sort this list of numbers as follows: 2nd col first, then 1st col, then 3rd col, all in reverse (highest to lowest). I'm doing this: sort -k 2,2nr -k 1,1nr -k 3,3gr but, as you see, the 3rd col does not get sorted properly. Any idea... (0 Replies)
Discussion started by: mamboknave
0 Replies

7. UNIX for Dummies Questions & Answers

Sort with multiple keys

Please suggest a sort command to achieve the below task. Thanks. I want to sort a file considering multiple keys. Sort Keys: Field 2, Field4 and Field6 Input file vqrs,16,zzz,1235,eq,T abcd,11,zzz,1234,pq,F abcd,10,zzz,1235,pq,F lqrs,15,zzz,1235,eq,T pqrs,12,zzz,1234,eq,F... (3 Replies)
Discussion started by: pretty1234
3 Replies

8. Shell Programming and Scripting

Perl - multiple keys and merging two files

Hi, I'm not a regular coder but some times I write some basic perl script, hence Perl is bit difficult for me :). I'm merging two files a.txt and b.txt into c.txt: a.txt ------ x001;frtb70;xyz;109 x001;frvt65;sec;239 x003;wqax34;jul;659 x004;yhud43;yhn;760 b.txt ------... (8 Replies)
Discussion started by: Lokesha
8 Replies

9. UNIX for Dummies Questions & Answers

Average for multiple keys

Hi, I want to find row-wise average of multiple columns based on 2 columns. I have 30k values in the matrix with 94 cols. Example Input for cols 4 and 5 as keys 1 2 3 a 1 4 5 6 a 1 4 2 0 a 1 1 2 3 b 2 5 6 7 b 2 9 7 5 b 2 Output 3 3 3 a 1 5 5 5 b 2Here is what I have tried,... (5 Replies)
Discussion started by: ritakadm
5 Replies

10. Shell Programming and Scripting

Find All duplicates based on multiple keys

Hi All, Input.txt 123,ABC,XYZ1,A01,IND,I68,IND,NN 123,ABC,XYZ1,A01,IND,I67,IND,NN 998,SGR,St,R834,scot,R834,scot,NN 985,SGR0399,St,R180,T15,R180,T1,YY 985,SGR0399,St,R180,T15,R180,T1,NN 985,SGR0399,St,R180,T15,R180,T1,NN 2943,SGR?99,St,R68,Scot,R77,Scot,YY... (2 Replies)
Discussion started by: unme
2 Replies
GROLBP(1)						      General Commands Manual							 GROLBP(1)

NAME
grolbp - groff driver for Canon CAPSL printers (LBP-4 and LBP-8 series laser printers). SYNOPSIS
grolpb [ -l ] [ --landscape ] [ -v ] [ --version ] [ -cn ] [ --copies=numcopies ] [ -ppaper_size ] [ --papersize=paper_size ] [ -oorientation ] [ --orientation=orientation ] [ -wwidth ] [ --linewidth=width ] [ -Fdir ] [ --fontdir=dir ] [ -h ] [ --help ] [ files... ] DESCRIPTION
grolbp is a driver for groff that produces output in CAPSL and VDM format suitable for Canon LBP-4 and LBP-8 printers. For compatibility with grolj4 there is an additional drawing command available: D'R dh dv' Draw a rule (i.e. a solid black rectangle), with one corner at the current position, and the diagonally opposite corner at the cur- rent position +(dh,dv). OPTIONS
Note that there can be whitespace between a one-letter option and its argument; on the other hand, there must be whitespace and/or an equal sign (`=') between a long-name option and its argument. -cnumcopies --copies=numcopies Print numcopies copies of each page. -l --landscape Print the document with a landscape orientation. -ppaper_size --papersize=paper_size Set the paper size to paper_size, which must be a valid paper size description as indicated in the section PAPER SIZES. -oorientation --orientation=orientation Print the document with orientation orientation, which must be `portrait' or `landscape'. -wwidth --linewidth=width Set the default line thickness to width thousandths of an em. If this option isn't specified, the line thickness defaults to 0.04 em. -v --version Print the version number. -Fdir --fontdir=dir Prepend directory dir/devname to the search path for font and device description files; name is the name of the device, usually lbp. -h --help Print a short help text. TYPEFACES
The driver supports the Dutch, Swiss and Swiss-Narrow scalable typefaces, each one in the Regular, Bold, Italic and Bold-Italic styles. Additionally, the Courier and Elite monospaced typefaces at the sizes 8 and 12 points (for Courier) resp. 8 and 10 points (for Elite) are supported, each one in the Regular, Bold and Italic styles. The following chart summarizes the font names you can use to access these fonts: +----------------+-----------+--------+----------+--------------+ | Typeface | Regular | Bold | Italic | Bold-Italic | +----------------+-----------+--------+----------+--------------+ | Dutch | TR | TB | TI | TBI | +----------------+-----------+--------+----------+--------------+ | Swiss | HR | HB | HI | HBI | +----------------+-----------+--------+----------+--------------+ | Swiss Narrow | HNR | HNB | HNI | HNBI | +----------------+-----------+--------+----------+--------------+ | Courier | CR | CB | CI | | +----------------+-----------+--------+----------+--------------+ | Elite | ER | EB | EI | | +----------------+-----------+--------+----------+--------------+ PAPER SIZES
The paper size can be set in the DESC file or with command line options to grolbp. If the paper size is specified both ways, the command line options take precedence over the contents of the DESC file (this applies to the page orientation too). See groff_font(5) how to set the paper dimensions in the DESC file. To set the paper size in the command line, add -p paper-size or --papersize=paper-size to the other grolbp options, where paper-size is in the same format as in the DESC file. If no paper size is specified in the DESC file or the command line, a default size of A4 is used. PAGE ORIENTATION
As with the page size, the orientation of the printed page (portrait or landscape) can be set in the DESC file or with command line op- tions. It is also case insensitive. To set the orientation in the DESC file, insert a line with the following content: orientation [portrait|landscape] Only the first valid orientation command in the DESC file is used. To set the page orientation with command line options you can use the -o or --orientation option with the same parameters (portrait or landscape) as in the DESC file. Or you can use the -l option to force the pages to be printed in landscape. FONT FILE FORMAT
In addition to the usual commands described in groff_font(5), grolbp provides the command lbpname which sets the font name sent to the printer when requesting this font. The syntax of this command is: lbpname printer_font_name o For bitmapped fonts, printer_font_name has the form N<base_fontname><font_style> base_fontname is the font name as it appears in the printers font listings without the first letter, up to (but not including) the font size. font_style can be one of the letters R, I, or B, indicating the font styles Roman, Italic and Bold respectively. For instance, if the printer's font listing A shows font `Nelite12I.ISO_USA', the corresponding entry in the font description file is lbpname NeliteI Note that you may need to modify grolbp to add support for new bitmapped fonts, since the available font names and font sizes of bitmapped fonts (as documented above) are hard-coded into the program. o For scalable fonts, printer_font_name is identical to the font name as it appears in the printer's font listing A. For instance, to select the `Swiss' font in bold style, which appears in the printer's font listing A as `Swiss-Bold', the required lbpname command line is lbpname Swiss-Bold The argument of lbpname is case sensitive. ENVIRONMENT
GROFF_FONT_PATH A list of directories in which to search for the devname directory in addition to the default ones. See troff(1) and groff_font(5) for more details. FILES
/usr/share/groff/1.21/font/devlbp/DESC Device description file. /usr/share/groff/1.21/font/devlbp/F Font description file for font F. /usr/share/groff/1.21/tmac/lbp.tmac Macros for use with grolbp. SEE ALSO
groff(1), troff(1), groff_out(5), groff_font(5), groff_char(7) Groff Version 1.21 31 December 2010 GROLBP(1)
All times are GMT -4. The time now is 03:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy